How to Enhance Dynamics GP’s Inventory BOM Report Using SSRS

During a recent project for a client they want to enhance their custom inventory BOM report made by another vendor. Not having access to the original code, I proposed modifying the Bill of Materials Maintenance window to add a print button and developing the report in SSRS.

Here’s how to enhance Dynamics GP‘s inventory BOM report using SSRS.

Modifying the window

1. Log into Dynamics GP and open the Bill of Material Maintenance window in the Inventory Module.
2. On the window navigate to Tools>>Customize>>Modify Current Window. This will open modifier.

3. Inside of Modifier, click on the “OK” button from the toolbox on the left and drag it onto menu bar of the Bill of Material Maintenance window. As shown on the below screen shot.

4. Open the Properties of the new “OK” button and change the text for the button. I changed mine to “Print BOM”. Save the changes and Exit Modifier to get back into Dynamics GP.

Adding VBA code to our window

1. With the Window now modified, we need to navigate back to Tools>>Customize>>Add Current Window to Visual Basic. We also need to add the “Print BOM” button and Bill Number field to Visual Basic by selecting the “Add Fields to Visual Basic…” menu.

2. Now open up Visual Basic Editor, Tools>>Customize. We need to make the button functional by adding some VBA code.

a. First let’s add the References that we need for the project by navigating to Tools>>References from the menu bar. Add or verify that the following References are selected: Visual Basic for Applications, Microsoft Dynamics GP VBA 18.0 Type Library, OLE Automation and Microsoft ActiveX Data Objects 2.1 Library.

b. Before writing our VBA code we should verified that the window and both fields were added to the VBA project. We can do that by click on the dropdown menu where you see “(General)”. Your screen should look similar to my screen shot below.

c. Add the following VBA code Object Browser. You will need to change the highlighted VBA code based your SSRS server name, folder location of the report that we will be building and the name of the SSRS report. In the VBA code below:
i. XXXXX – would be my SSRS server name
ii. TWO – is the Folder that I saved the report in
iii. BOM Indented is what I named my report

Sub window_Open(strLocation As String, Menubar As Boolean, top As Long, left As Long, height As Long, width As Long, resizable As Boolean)

With CreateObject(“InternetExplorer.Application”)
.Visible = False
.top = top
.left = left
.height = height
.width = width
.Menubar = Menubar
.Visible = True
.resizable = resizable
.Navigate strLocation

End With

End Sub

Private Sub PrintBOM_BeforeUserChanged(KeepFocus As Boolean, CancelLogic As Boolean)
Dim IBOM
Dim IE As Object

IBOM = CStr(BillNumber)

window_Open “http://XXXXXXX/ReportServer/Pages/ReportViewer.aspx?%2fTWO%2fBOM+Indented&rs:Command=Render&BOMItem=” & IBOM & vtype, False, 10, 10, 750, 1250, True

End Sub

Creating the stored procedures for the SSRS report.

Now the tricky part, dealing with the undefined amount of levels that a BOM hierarchy can go down. With the help of Google, I found this forum post – https://community.dynamics.com/gp/f/32/t/39209?pi53330=2#responses. Original credit and thanks to Beat Bucher and Tim Foster for the post and original SQL code. I have modified the original stored procedure to fit my client’s needs. Here is the stored procedure code that I used:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[usp_BOM_Level_Details] (@current char(31)–, @BOMType smallint
) AS
/*
DROP TABLE #result;
Drop Table #stack;
*/
–DECLARE @current char(31) –> use the 2 lines here to test directly in SQL Studio Mgmt
–SET @current=’BB00069E0000BT9′
SET NOCOUNT ON
–if @current is null set @current = ‘BB00069E0000BT9’
DECLARE @lvl int, @line char(31), @Qty numeric(19,5), @ORD1 int, @UOFM char(9), @comptitm char(31)
CREATE TABLE #stack (item char(31), comptitm char(31), Design_Qty numeric(19,5), ORD1 int, UOFM char(9), lvl int)
CREATE TABLE #result (lvl int, item char(31), comptitm char(31), Qty numeric(19,5), ORD1 int, UOFM char(9),
ord int identity(1,1))
INSERT INTO #stack VALUES (@current, ”,1,1,”,1)
SELECT @lvl = 1
WHILE @lvl > 0
BEGIN
IF EXISTS (SELECT * FROM #stack WHERE lvl = @lvl)
BEGIN
SELECT @current = item, @comptitm = comptitm, @Qty = Design_Qty, @ORD1 = ORD1, @UOFM = UOFM
FROM #stack
WHERE lvl = @lvl
— SELECT @line = replicate(‘-‘,(@lvl – 1)) + ‘ ‘ + @current –> spacing by level
–PRINT @line –> replace this print with an INSERT to another table like #BOM
INSERT #result SELECT @lvl,@current, @comptitm, @Qty, @ORD1, @UOFM
DELETE FROM #stack
WHERE lvl = @lvl
AND item = @current
INSERT #stack
SELECT CMPTITNM, ITEMNMBR, Design_Qty, ORD, UOFM, @lvl + 1
FROM BM00111 –> I edited this for GP
WHERE ITEMNMBR = @current and Component_Status = 1 –and BOMCAT_I = @BOMType –1 –> added BOMCAT for MFG(1) or ENG(2)
ORDER BY ORD –Order by Part Number as in GP Reports CMPTITNM
–ORDER BY POSITION_NUMBER ASC –Order by Position Number–other sequence in GP
IF @@ROWCOUNT > 0
SELECT @lvl = @lvl + 1
END
ELSE
SELECT @lvl = @lvl – 1
END — WHILE
drop table #stack
;WITH CTE as (select ITEMNMBR FROM BM00101)
SELECT T1.lvl,
CASE WHEN T1.lvl = 1 THEN ”
ELSE RTRIM(T1.item)
END as item,
CASE WHEN T1.lvl = 1 THEN RTRIM(T1.item)
ELSE RTRIM(T1.comptitm)
END as comptitm,
T1.Qty, T1.ORD1,
RTRIM(T1.UOFM) as UOFM,
T1.ord
,T2.ITEMDESC
,T2.STNDCOST
,CASE WHEN T1.item in (select ITEMNMBR FROM CTE)
THEN 0
ELSE T2.CURRCOST
END AS CURRCOST
,CASE WHEN T1.item in (select ITEMNMBR FROM CTE) THEN 0
ELSE (T2.CURRCOST * T1.Qty)
END as [Ext Cost]
FROM
#result T1 INNER JOIN IV00101 T2
ON T2.ITEMNMBR = T1.item

ORDER BY ord;
DROP TABLE #result;

GO

Building our SSRS BOM Indented Report

SSRS (SQL Server Reporting Services) is a server-based reporting system from Microsoft and part of the SQL server stack. It can be used to prepare and deliver prints through a web site. You can build your reports with either Report Builder or Visual Studio. For this project, we are going to be using Report Builder. Let’s start creating our Indented BOM report using a wizard.
Creating the Data Connection
1. Start Report Builder either from your computer or the Reporting Services web portal. Select New Report in the left pane and Table or Matrix Wizard in the right pane.


2. Specify a Data Connection in the Table Wizard
A data connection contains the information to connect to an external data source such as a SQL Server database. Usually, you get the connection information and the type of credentials to use from the data source owner. To specify a data connection, you can use a shared data source from the report server or create an embedded data source that is used only in this report.
3. Click the New Button to create a new Data Source and then build on the Data Source Properties window that opens.


4. Enter your Connection Properties for the SQL Server and Dynamics GP company database.

5. Click the General tab again. To verify that you can connect to the data source, click Test Connection.
The message “Connection created successfully” appears.
6. Click OK.

Creating our Datasets

1. Right click on your new Data Source to create a Dataset.
2. Choose to use a dataset embedded in my report and a Query type of Stored Procedure. Choose the stored procedure we created earlier. (usp_BOM_Level_Details)

3. Add a Parameter for the Dataset Properties. I named mine @BOMItem
Organize Data into Groups in the Table Wizard
When you select fields to group on, you design a table that has rows and columns that display detail data and aggregated data. To start organizing your data into groups:
1. Navigate to the Insert menu, click on the Table icon and select Table Wizard.

2. On the New Table or Matrix window drag the lvl, comptitm, item, ITEMDESC and UOFM to the Row Groups section. Drag the Qty, CURRCOST and Ext_Cost fields to the Values Section.

3. Click Next and de-select Expand/collapse groups.

4. Remove the sub-grouping totals, format the numbers to the forth decimal place and change the row height to 0.025. Your table should look like the below screen shot when your complete.

5. Change the Tablix Properties for the Row and Column Headers to Repeat on each page.

The Final Product

Once complete, you should have a Dynamics GP Bill of Materials Maintenance window like the below screen shot and when you select a Bill Number and click the Print BOM button the SSRS report will open and produce the results in the second screen shot. You can download zip file the stored procedure, Dynamics GP package file and SSRS rdl report from here.

Ready to Do Even More with Dynamics?

As a full-service technology consulting company, KTL Solutions works with business leaders every day in helping them lead their organization into becoming data-driven organization by exploring your Business Intelligence, BI360, Power BI, Microsoft Dynamics GP and CRM journey. Need help with your journey?

Share this post

Related Posts

Checking Your CMMC Progress

Written by Alec Toloczko With Cybersecurity Maturity Model Certification (CMMC) requirements on the horizon, it’s crucial for organizations handling Controlled Unclassified Information (CUI) to adhere

Read More »