The Dev Guy

The Dev Guy

Thursday, April 30, 2015

Passing Parameters in Dynamics SL Screen and Insert into Grid


Goal 

You have a SL Dynamics custom screen with a grid. You want to pass parameters to this screen from another screen and, if values are passed, you want to insert a new line in the grid, put the values in it but Not save the line unless the user hits save. 
I recently had to do this where there was a bank feed that had vendor sometimes missing from the file but had a vendor name. So I created a cross walk table that has the bank feed vendor and name and the user  selected vendor id that it should walk to.  The user would select the line with the issue and click a button to add the vendor passed and the vendor name to the cross walk table.   

Environment

SQL 2008, Windows Server 2008 for SL and SQL Server, Windows 7 workstations, and Dynamics SL 2011.

We are developing in Visual Studio 2010. Please see my other post on how to get around the 64 bit issue.

Issue

            The problem is just figuring what code to use to perform these tasks: 
1) check parameters if passed
2) insert new blank line into grid on the fly
3) place values passed into this new blank line 

Resolution                                             

            The Resolution was as follows:
1) use ApplSetParmValue and ApplGetParmValue functions to pass and read the parameters.
2) use Edit_New() sub to insert new blank line into grid
3) use SetObjectValue functions to set the grid to have the values passed
 

Code in Calling Program:

Call ApplSetParmValue(PRMSECTION_VBRDT, "BankVendorID", sBank)

Call ApplSetParmValue(PRMSECTION_VBRDT, "VENDORName", sVendorName)
Code in Browse window Program (this is added to the form load after the detailload of the grid:

Dim sVendorID As String

Dim sVendorName As String

sVendorID = ApplGetParmValue(PRMSECTION_VBRDT, "BankVendorID")

sVendorName = ApplGetParmValue(PRMSECTION_VBRDT, "VENDORName")
 
Code to check if passed and insert line to grid:

If sVendorID <> "" or sVendorName <> "" Then

          
Edit_New(LEVEL0)
 
serr9 = SetObjectValue(txtVendorID, Mid(sVendorID, 1, 10))

serr9 = SetObjectValue(txtVendorName, Mid(sVendorName, 1, 30))
 
End If

The code checks if either of the parameters filled the memory fields.
if so Edit_New is passed the level that the grid is on and inserts a value. The focus is always set to this new line. That's why I chose the Edit_New.
Finally using SetObjectValue set the text fields for the values passed. 
That's it!

Conclusion 

 

It is relatively easy to pass parameters and add to a grid on the fly, allowing the user to accept or reject the changes before they are saved using the Solomon RDT Toolkit.