Thursday, October 15, 2009

Practical Example on Dynamics Continuum Integration Library: GL Transaction Entry Integration

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:

References:

In order to start working on the API, we need first to add Reference to Dynamics Continuum Integration Library to our application:

image

Now we have three main functions/methods that we need to use:

 

Functions/Methods:

1. ExecuteSanscript: Function executes Dexterity code and return the result, expects two parameters and returns integer that the status was successfully completed or not:

ExecuteSanscript("Script" as String, ByRef "ErrorMessage" As String)

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:

SetDataValue("Field Name" as String, Value as String)

3. MoveToField: Moves the cursor to the field, expects only the field name as the parameter, almost equivalent to "focus field" command in Dexterity:

MoveToField("Field Name" as String)

 

Concept:

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.

 

Code Snippets:





 




'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)


'------------------------------------------------------------------------------'


 



That's it! Let me know if you have any issues or inquiries about the above code, I will be more than happy to help.


Regards,

--


Mohammad R. Daoud


MVP, MCP, MCT, MCBMSP, MCTS, MCBMSS


CTO


+962 - 79 - 999 65 85


Dynamics Innovations


daoudm@dynamicsinnovations.com


http://www.dynamicsinnovations.com

13 comments:

Mohammad R. Daoud said...

http://blogs.msdn.com/developingfordynamicsgp/archive/2009/10/20/hybrid-development-and-continuum.aspx

Santosh Surti said...

This is very usefull...

Is it possible to upload GL Trx using this code?

If yes could you share some knowledge on it?

Regards,
Santosh

Mohammad R. Daoud said...

Santosh,

This was the main idea of publishing the above code, just loop your data and call this code inside and enjoy.

Regards,

Anonymous said...

Nice one! However is there any way we can disable window through sanscript?

emerson said...

Hi Sir,

i have learned a lot from your post as a newbie in integration of dynamics gp. May i ask how to set the value of [account number] which is a composite field? im really having a hard time setting the value of account number using cintinuum library. hope you have a piece of code to do it. thanks a lot.

emerson said...

saw the piece of code sir in your example. i have to run the script of account number to set the value. thanks a lot.

Anonymous said...

This post is vary valuable fou us.
Is the COM a common COM like ADO?
We have a SalesLogix CRM and its opened coding area is a VBScript-based environment. We can create ADO objects and then execute those propetyies and mathods. Can we use Dynamics Continuum in our SalesLogix form like we use ADO? e.g. we have a SalesLogix form on which there is a button. When the button is clicked, the GP invoice form should be opened and popped up. Is that possible?

Anonymous said...

Sorry about the typo mistakes "propetyies and mathods". It should be "properties and methods".

Sujana said...
This comment has been removed by the author.
Unknown said...

This post is quite helpful. Thank you!

I am stuck up with a problem while using Continuum on user defined forms. Say I have an user defined form called 'SOP_Extended' which is an extended form of 'Sales Transaction Entry'. When I use ExecuteSanscript of Continuum API to "open form 'SOP_Extended'" I am thrown with errorMessage "Unknown Identifier 'SOP_Extended'."

The difference I see is 'SOP_Entry' and the other forms of GP belog to the dictionary 'default'. Where as the extended form belong to dictionary 'PPM Extended Data'. Could you suggest me if there any way in which I can address this issue? Please let me know if I am not clear. Any help would be greatly appreciated. Thank you in advance!

wael said...

i have learned a lot from your post thank you very much

could you please give me a hand of how can I pass AccountNumber


I want to know what is AccountNumber format I have to use in above example

thank you very much

BhuvanPE said...
This comment has been removed by the author.
Victor Fabiano said...

Please help message Continuum:

Failed to register a focus notification on 'Zip' of window 'RM_Customer_Maintenance' of form 'RM_Customer_Maintenance'. The object does not exist.

Method
FocusRegistation("'Zip' of window 'RM_Customer_Maintenance' of form 'RM_Customer_Maintenance'", "cbDataEntryZip", TRIGGER_FOCUS_CHANGE, TRIGGER_BEFORE_ORIGINAL)

Related Posts:

Related Posts with Thumbnails