I got allot of questions on how to use Dynamics Continuum API for Microsoft Dynamics GP, so I decided to post this practical lesson on how to perform forms level integration between any application or data source and GL Transaction Entry form:
In order to start working on the API, we need first to add Reference to Dynamics Continuum Integration Library to our application:
1. ExecuteSanscript: Function executes Dexterity code and return the result, expects two parameters and returns integer that the status was successfully completed or not:
2. SetDataValue: Function sets value in any "fully qualified" field name, expects two parameters and returns integer that the status was successfully completed or not:
3. MoveToField: Moves the cursor to the field, expects only the field name as the parameter, almost equivalent to "focus field" command in Dexterity:
To proceed with our task, we'll need first to understand how it works, we'll need to imagine that a user is working on the form and follow all the steps need to be done, for example, the user will go to date field, fill the date and leave the field so the system run all validations on date field leave, technically speaking "MoveToField" will need to be called first, then "SetDataValue" and finally "ExecuteSanScript" to run the required scripts on leaving the field.
'Define the main object
Dim objGPApp As New Dynamics.Application
'Variable to Handle Returned Errors Flag
Dim intErrorValue As Integer
'Variable to Handle Returned Errors Messages
Dim strErrorMessage As String
'Other Needed Variables
Dim strBatchID As String = "Dataset Name"
Dim SourceDocument As String = "Source Document"
Dim TrxDate As String = "01012009"
Dim ReferenceID As String = "Sample"
Dim dsDetails As DataSet
'------------------------------------------------------------------------------
'Open the GL Transaction Entry Form
intErrorValue = objGPApp.ExecuteSanscript("open form 'GL_Transaction_Entry';", strErrorMessage)
'------------------------------------------------------------------------------'
'Add/Update Batch to make sure its exist
'Open Batch Entry Form
intErrorValue = objGPApp.ExecuteSanscript("run script 'Expansion Button 1' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry';", strErrorMessage)
'Fill Batch Number
intErrorValue = objGPApp.SetDataValue("'Batch Number' of window 'GL_Batch_Entry' of form 'GL_Batch_Entry'", strBatchID)
'Run Batch Number Script
intErrorValue = objGPApp.ExecuteSanscript("run script 'Batch Number' of window 'GL_Batch_Entry' of form 'GL_Batch_Entry';", strErrorMessage)
'Fill Origin
intErrorValue = objGPApp.SetDataValue("'Origin' of window 'GL_Batch_Entry' of form 'GL_Batch_Entry'", 1)
'Go To Batch Comment Field
intErrorValue = objGPApp.MoveToField("'Batch Comment' of window 'GL_Batch_Entry' of form 'GL_Batch_Entry'")
intErrorValue = objGPApp.ExecuteSanscript("run script 'Batch Comment' of window 'GL_Batch_Entry' of form 'GL_Batch_Entry';", strErrorMessage)
'Save Batch
intErrorValue = objGPApp.ExecuteSanscript("run script 'Save Button' of window 'GL_Batch_Entry' of form 'GL_Batch_Entry';", strErrorMessage)
'Close form
intErrorValue = objGPApp.ExecuteSanscript("close form 'GL_Batch_Entry';", strErrorMessage)
' End Batch
'------------------------------------------------------------------------------'
'Add/Update Source Document to make sure its exist
'Open Source Document Form
intErrorValue = objGPApp.ExecuteSanscript("open form 'SY_Source_Document_Setup';", strErrorMessage)
'Move to Source Document Field
intErrorValue = objGPApp.MoveToField("'Source Document' of window 'Source_Document_Setup' of form 'SY_Source_Document_Setup'")
'Set Field Value
intErrorValue = objGPApp.SetDataValue("'Source Document' of window 'Source_Document_Setup' of form 'SY_Source_Document_Setup'", SourceDocument)
'Run Field Script
intErrorValue = objGPApp.ExecuteSanscript("run script 'Source Document' of window 'Source_Document_Setup' of form 'SY_Source_Document_Setup';", strErrorMessage)
'Go To Description Field
intErrorValue = objGPApp.MoveToField("'Source Document Description' of window 'Source_Document_Setup' of form 'SY_Source_Document_Setup'")
'Set Data Value in Description Field
intErrorValue = objGPApp.SetDataValue("'Source Document Description' of window 'Source_Document_Setup' of form 'SY_Source_Document_Setup'", SourceDocument)
'Run Field Script
intErrorValue = objGPApp.ExecuteSanscript("run script 'Source Document Description' of window 'Source_Document_Setup' of form 'SY_Source_Document_Setup';", strErrorMessage)
'Save
intErrorValue = objGPApp.SetDataValue("'Save Button' of window 'Source_Document_Setup' of form 'SY_Source_Document_Setup'", 1)
'Close Form
intErrorValue = objGPApp.ExecuteSanscript("close form 'SY_Source_Document_Setup';", strErrorMessage)
'End Source Document Adding
'------------------------------------------------------------------------------'
'Now we are sure that the batch number and source document are both exist,
'so we can use both of them in our form
intErrorValue = objGPApp.MoveToField("'Batch Number' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry'")
intErrorValue = objGPApp.SetDataValue("'Batch Number' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry'", strBatchID)
intErrorValue = objGPApp.ExecuteSanscript("run script 'Batch Number' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry';", strErrorMessage)
intErrorValue = objGPApp.MoveToField("'Source Document' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry'")
intErrorValue = objGPApp.SetDataValue("'Source Document' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry'", SourceDocument)
intErrorValue = objGPApp.ExecuteSanscript("run script 'Source Document' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry';", strErrorMessage)
'------------------------------------------------------------------------------'
'Proceed with Journal Header Fill
'Reference
intErrorValue = objGPApp.MoveToField("'Reference' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry'")
intErrorValue = objGPApp.SetDataValue("'Reference' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry'", ReferenceID)
intErrorValue = objGPApp.ExecuteSanscript("run script 'Reference' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry';", strErrorMessage)
'Transaction Date -You need to make sure that you passed the date
'in the correct format-
intErrorValue = objGPApp.MoveToField("'TRX Date' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry'")
intErrorValue = objGPApp.SetDataValue("'TRX Date' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry'", TrxDate)
intErrorValue = objGPApp.ExecuteSanscript("run script 'TRX Date' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry';", strErrorMessage)
'End of Journal Header
'------------------------------------------------------------------------------'
'Journal Details: in this example, I considered the data is already filled in
'a dataset called dsDetails with the following columns:
'(AccountNumber, AccountType ('Credit', 'Debit'), AccountAmount, LineDescription)
'------------------------------------------------------------------------------'
'Loop through all details
For Counter As Integer = 0 To dsDetails.Tables(0).Rows.Count - 1
With dsDetails.Tables(0).Rows(Counter)
'Start with Account Number
intErrorValue = objGPApp.ExecuteSanscript("focus field 'Account Number' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry';", strErrorMessage)
intErrorValue = objGPApp.MoveToField("'Account Number' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry'")
intErrorValue = objGPApp.SetDataValue("'Account Number' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry'", .Item("AccountNumber"))
intErrorValue = objGPApp.ExecuteSanscript("run script 'Account Number' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry';", strErrorMessage)
'Check the account type, credit or debit
If Trim(.Item("AccountType")).ToLower = "Debit".ToLower Then
'Incase of Debit, fill debit with the amount
intErrorValue = objGPApp.ExecuteSanscript("focus field 'Debit Amount' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry';", strErrorMessage)
intErrorValue = objGPApp.MoveToField("'Debit Amount' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry'")
intErrorValue = objGPApp.SetDataValue("'Debit Amount' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry'", .Item("AccountAmount"))
intErrorValue = objGPApp.ExecuteSanscript("run script 'Debit Amount' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry';", strErrorMessage)
intErrorValue = objGPApp.ExecuteSanscript("focus field 'Credit Amount' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry';", strErrorMessage)
intErrorValue = objGPApp.MoveToField("'Credit Amount' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry'")
Else
'Incase of credit, fill credit field with the amount
intErrorValue = objGPApp.ExecuteSanscript("focus field 'Credit Amount' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry';", strErrorMessage)
intErrorValue = objGPApp.MoveToField("'Credit Amount' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry'")
intErrorValue = objGPApp.SetDataValue("'Credit Amount' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry'", .Item("AccountAmount"))
intErrorValue = objGPApp.ExecuteSanscript("run script 'Credit Amount' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry';", strErrorMessage)
End If
'Fill the distribution reference field
intErrorValue = objGPApp.ExecuteSanscript("focus field 'Description' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry';", strErrorMessage)
intErrorValue = objGPApp.MoveToField("'Description' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry'")
intErrorValue = objGPApp.SetDataValue("'Description' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry'", .Item("LineDescription"))
intErrorValue = objGPApp.ExecuteSanscript("run script 'Description' of window 'Transaction_Scroll' of form 'GL_Transaction_Entry';", strErrorMessage)
'Move the scrolling window to the next line
intErrorValue = objGPApp.ExecuteSanscript("Window_ScrollScrollingWindow(window 'Transaction_Scroll' of form 'GL_Transaction_Entry', SCROLLTYPE_NEXT);", strErrorMessage)
End With
Next
'Save the Journal
intErrorValue = objGPApp.ExecuteSanscript("run script 'Save Button' of window 'GL_Transaction_Entry' of form 'GL_Transaction_Entry';", strErrorMessage)
'Close GL Transaction Entry Form
intErrorValue = objGPApp.ExecuteSanscript("close form 'GL_Transaction_Entry';", strErrorMessage)
'------------------------------------------------------------------------------'