VBA Snippets: Adding an SQL ODBC Connection in Microsoft Dynamics GP

MicrosoftThis post is part of the series on VBA Snippets.

There is an ADO connection available to VBA within Microsoft Dynamics GP which you can use, but there are some steps you need to follow to use it.

The first step is to declare the variable which will hold the connection.

Private madoConn AS ADODB.Connection

Then you need to create the connection which this example does using a Connect subroutine:

Private Sub Connect()
	If madoConn.State <> adStateOpen Then 
		Set madoConn = UserInfoGet.CreateADOConnection
		madoConn.DefaultDatabase = UserInfoGet.IntercompanyID
	End If
End Sub

It checks if the connection is already open and, if not, uses the UserInfoGet object which holds the connection detail exposed in Dynamics GP; I am also using the same object to set the default database property.

Once connected you can use the connection to execute SQL queries; I’ll show some examples of this in later posts.

When you’re finished with the connection, you can close and destroy the connection:

Private Sub Disconnect()
    If madoConn.State = adStateOpen Then madoConn.Close
    Set madoConn = Nothing
End Sub

SQL Query to get First Level Items from Microsoft Dynamics GP Manufacturing BOM

Microsoft Dynamics GPWe’re currently doing some work for a client using the Manufacturing module of Microsoft Dynamics GP and I’ve been involved in the periphery of the manufacturing element while focusing on the financial and distribution parts, but have been assisting with some reporting items. One of them was to help create a report on the Mfg BOM showing only the first level items.

The below script, against the client data, gave the result which was required:

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
SELECT ['Mfg Order Master'].MANUFACTUREORDER_I ,['Mfg Order Master'].ITEMNMBR ,['Item Master'].ITEMDESC ,['Mfg Order Master'].ENDQTY_I ,['Inventory U of M Schedule Setup'].BASEUOFM ,['Bill Of Material Line File'].CPN_I FROM WO010032 AS ['Mfg Order Master'] --WO010032 INNER JOIN IV00101 AS ['Item Master'] --Item Master (IV00101) ON ['Item Master'].ITEMNMBR = ['Mfg Order Master'].ITEMNMBR INNER JOIN IV40201 AS ['Inventory U of M Schedule Setup'] --Inventory U of M Schedule Setup (IV40201) ON ['Inventory U of M Schedule Setup'].UOMSCHDL = ['Item Master'].UOMSCHDL INNER JOIN BM010115 AS ['Bill Of Material Line File'] --BM010115 ON ['Bill Of Material Line File'].PPN_I = ['Mfg Order Master'].ITEMNMBR

Find All Microsoft Dynamics GP Companies With Web Services Enabled

Microsoft Dynamics GPI’ve recently been doing some work with a client which necessitated the backup of all databases using the Web Services for Microsoft Dynamics GP. The easiest way to determine which databases had the web services enabled, was to run a script checking the Workflow Setup (WF00100) table.

I took a copy of my return functional currency for all companies script and amended it to look at the web services.

If the web services has never been enabled, a company won’t be returned at all other wise a 1 for active or 0 for inactive will be returned.

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
CREATE TABLE #Workflow( INTERID VARCHAR(5) ,CMPNYNAM VARCHAR(200) ,WEBSERVICESACTIVE VARCHAR(20) ) GO DECLARE @SQL NVARCHAR(MAX) SELECT @SQL = STUFF(( SELECT CHAR(13) + 'SELECT ''' + INTERID + ''' ,''' + CMPNYNAM + ''' ,EnableWFNotifService FROM ' + INTERID + '.dbo.WF00100' FROM DYNAMICS.dbo.SY01500 FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') INSERT INTO #Workflow EXEC sys.sp_executesql @SQL GO SELECT * FROM #Workflow ORDER BY INTERID GO DROP TABLE #Workflow GO

SQL View to Return Microsoft Dynamics GP Item Number Split by Hyphens

Microsoft Dynamics GPAs with most of the other views I have posted, this is one I have written a few times over the years and am now posting it to make it easy to find next time I need it.

This view returns the Item Number from the Item Master (IV00101) table split into sections by hyphens. It assumes the item number has up to three sections, but can easily be extended.

With the view deployed, it can easily be included in any reporting tool, such as SmartList Designer/Builder or a refreshable Excel Report.

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
-- drop view if it exists IF OBJECT_ID(N'uv_AZRCRV_ItemNumberSplitByHyphens', N'V') IS NOT NULL DROP VIEW uv_AZRCRV_ItemNumberSplitByHyphens GO -- create view CREATE VIEW uv_AZRCRV_ItemNumberSplitByHyphens AS SELECT DISTINCT ITEMNMBR ,RTRIM(SUBSTRING(REPLACE(ITEMNMBR, '-', REPLICATE(' ', LEN(ITEMNMBR))), (0) * LEN(ITEMNMBR)+1, LEN(ITEMNMBR))) AS SECTION_1 ,RTRIM(SUBSTRING(REPLACE(ITEMNMBR, '-', REPLICATE(' ', LEN(ITEMNMBR))), (1) * LEN(ITEMNMBR)+1, LEN(ITEMNMBR))) AS SECTION_2 ,RTRIM(SUBSTRING(REPLACE(ITEMNMBR, '-', REPLICATE(' ', LEN(ITEMNMBR))), (2) * LEN(ITEMNMBR)+1, LEN(ITEMNMBR))) AS SECTION_3 FROM IV00101 AS ['Item Master'] WITH (NOLOCK) --Item Master (IV00101) GO GRANT SELECT ON uv_AZRCRV_ItemNumberSplitByHyphens TO DYNGRP GO

It would also be quite easy to amend the view to split out other strings based on a character using a variation of the above SQL script.

Microsoft Dynamics GP Purchasing All-In-One View Product 258 Error

Microsoft Dynamics GPI’m working on an implementation project at the moment to migrate a company from an older ERP into Microsoft Dynamics GP for an existing client using Dynamics GP and have been doing a lot of training. One area I covered was the All-in-One View enquiries in Purchasing, Inventory and Sales. After the training one of the users have exploring the system and found that the drilldown from an invoice on the Purchasing All-in-One View (Purchasing area page » Inquiries » Purchasing All-in-One View) wasn’t working.

We hadn’t noticed this in training as I had used a payment and purchase order as examples of the drill down. The error the client was seeing was this:

Error Message

Unhandled script exception:
Invalid Product ID 258.

EXCEPTION_CLASS_SCRIPT_OUT_OF_RANGE
SCRIPT_CMD_CALL

It rang a bell and when I checked found a post by Mariano Gomez in 2017 where he found this error in Dynamics GP 2015 R2 and 2016 RTM; I tested and it is also in 2018 and 2018 R2, but not in 2019 or 2020.

In the comments of Mariano’s blog, someone commented that marking and unmarking the Project Accounting entry ()Project Accounting is product 258) in the Registration window (Administration area page » Setup » System » ). I tested this on my system and it did remove the error so can discuss this workaround with the client.

Upcoming Microsoft Dynamics GP Webinars from ISC Software

ISC Software SolutionsEvery month at ISC Software I present a webinar on Microsoft Dynamics GP and related products. We typically have the next three upcoming monthly webinars I’ll be delivering scheduled.

We run these webinars on a monthly basis, with occasional extra webinars added to the schedule so it is worth checking the Webinar Schedule page every so often.

The upcoming webinars are:

Business Intelligence with Microsoft Dynamics GP
In May is Controls and Security in Microsoft Dynamics GP; Discover how Business Intelligence can improve visibility and help you make better, more timely, decisions.

Tue, May 18th, 2021 4:00 PM – 4:45 PM BST

Use Jet Analytics to harness multiple data sources for fast, reliable reporting and analytics. Through OLAP cubes and tabular models, you can easily report inside Excel or Power BI, with no coding and without requiring technical expertise.

Use PowerBI to create interactive, immersive dashboards and reports that provide actionable insights and drive business results.

Register Here

Personalising  Microsoft Dynamics GP
In June is Personalising Microsoft Dynamics GP; Learn how users can personalise their Dynamics GP experience.

Tue, June 15th, 2021 4:00 PM – 4:45 PM BST

In this webinar we’ll take a look at the standard functionality in Dynamics GP which allows users to tailor their homepage to fit their needs and ways they can use this to work smarter, not harder

Register Here

Lesser Used Modules in Dynamics GP
In July is Lesser Used Modules in Dynamics GP; Explore some of the lesser used modules of Microsoft Dynamics GP and how they can improve processes.

Tue, July 20th, 2021 4:00 PM – 4:45 PM BST

This webinar will look at the modules included in the Microsoft Dynamics GP Starter and Extended Packs, picking out some of the modules which can save time but which aren’t as commonly used.

Register Here

GeneralUser Error When Migrating Management Reporter to a New Server

Microsoft Dynamics GPAcross the years since it was launched I have done a lot of work with Management Reporter, including many migrations to new servers and upgrades which necessitated a migration to a new server or instance of SQL Server, but have never seen this particular error message before.

In this case, I migrated the Management Reporter database to a new server and installed the very latest version of the server software. When I started the database configuration, I received this error message:

Database configuration error

Validation Messages

Database configuration: The connection to the database was successful, but the connection to database 'Management Reporter' failed. Verify that the Management Reporter service account has been added to the General User role in the database.

Continue reading “GeneralUser Error When Migrating Management Reporter to a New Server”

Update Microsoft Dynamics GP Customer Emails on Test Including Sent Emails

Microsoft Dynamics GPAfter creating a new script for updating vendor emails on test which includes the emails of sent items, I figured that a similar script will be needed to update the email address on sent emails in the Sales Series.

The script below, includes the tables holding sent email information for the Sales Series emails (both Receivables Management and Sales Order Processing) as well as the usual Internet Addresses table; the highlighted email address can be changed to whatever email address you’re using for testing your Sales emails:

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
DECLARE @TestEmail VARCHAR(100) SET @TestEmail = 'email@example.com' -- UPDATE existing email addresses UPDATE SY01200 --Internet Addresses (SY01200) SET INET1 = @TestEmail ,EmailToAddress = @TestEmail ,EmailCcAddress = '' ,EmailBccAddress = '' WHERE Master_Type = 'CUS' -- UPDATE Email Details of previously sent emails UPDATE SY04910 --Email Details (SY04910) SET EmailToAddress = @TestEmail ,EmailCcAddress = CASE WHEN LEN(CAST(EmailCcAddress AS VARCHAR(1000))) = 0 THEN '' ELSE @TestEmail END WHERE MODULE1 IN (9,11) -- Receivables Management / Purchase Order Processing -- UPDATE Email Details of previously sent emails UPDATE SY04915 --Email History (SY04915) SET EmailToAddress = @TestEmail ,EmailCcAddress = CASE WHEN LEN(CAST(EmailCcAddress AS VARCHAR(1000))) = 0 THEN '' ELSE @TestEmail END WHERE MODULE1 IN (9,11) -- Receivables Management / Purchase Order Processing GO

Update Microsoft Dynamics GP Vendor Emails on Test Including Sent Emails

Microsoft Dynamics GPAbout 10 years ago I did a post on changing emails on the test system so they didn’t go outside the organisation. This has worked well for a long time and no-one has mentioned any issues, until this week when I was working with a client and we made some changes to a remittance format and tested by emailing.

The remittance itself emailed to the test address fine, but the reprint remittance went to the original email address of the vendor used on the live system.

After doing a little exploring I found there were two additional tables which held this data for sent emails and which were used by the reprint remittance function.

The script below, includes the Internet Addresses table as well as these two tables for the Purchasing Series emails (both Purchase Order Processing and Payables Management); the highlighted email address can be changed to whatever email address you’re using for testing your Purchasing emails:

/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
DECLARE @TestEmail VARCHAR(100) SET @TestEmail = 'email@example.com' -- UPDATE existing email addresses UPDATE SY01200 --Internet Addresses (SY01200) SET INET1 = @TestEmail ,EmailToAddress = @TestEmail ,EmailCcAddress = '' ,EmailBccAddress = '' WHERE Master_Type = 'VEN' -- UPDATE Email Details of previously sent emails UPDATE SY04910 --Email Details (SY04910) SET EmailToAddress = @TestEmail ,EmailCcAddress = CASE WHEN LEN(CAST(EmailCcAddress AS VARCHAR(1000))) = 0 THEN '' ELSE @TestEmail END WHERE MODULE1 IN (12,19) -- Purchase Order Processing / Payables Management -- UPDATE Email Details of previously sent emails UPDATE SY04915 --Email History (SY04915) SET EmailToAddress = @TestEmail ,EmailCcAddress = CASE WHEN LEN(CAST(EmailCcAddress AS VARCHAR(1000))) = 0 THEN '' ELSE @TestEmail END WHERE MODULE1 IN (12,19) -- Purchase Order Processing / Payables Management GO

Recent ISC Software Webinar: Powerful document generation for Dynamics GP

ISC Software SolutionsIn our most recent webinar, we took a look at Powerful document generation for Dynamics GP. In this webinar, we covered how dox42 can be used to design attractive document templates in Microsoft Office and integrate data from Microsoft Dynamics GP and other systems such as SharePoint or Microsoft 365. If you want to catch up on this, or any other, webinar, you can do so here.

In this blog post, I am going to recap the webinar and show the benefits and some example uses of dox42 for generating documents with data from Dynamics GP and other systems:

  1. Introducing dox42
  2. Examples of how dox42 can be used
  3. Template Design
  4. Integrate data from various sources
  5. Automate your output
  6. Key benefits
  7. Examples from Dynamics GP
  8. Conclusion

Introducing dox42 ^

dox42 are headquartered in Vienna Austria and sell dox42 through a partner channel using companies such as ISC Software. It allows you to generate individualised documents from all your existing systems, including Microsoft Dynamics GP, automatically. Offers, quotes, contracts, inspections or server-reports, presentations, Excel-charts and insurance policies; dox42 is a flexible, powerful and intuitive application which allows you to use the common interface of Microsoft Word, Excel or PowerPoint to design document templates.

Continue reading “Recent ISC Software Webinar: Powerful document generation for Dynamics GP”