GP/QTP Automation: Executing sanScript
All related posts: Reference Page – GP/QTP Automation
General concept
The Application object provides only a few methods for simulation of GUI interaction required in Test Automation. However, ExecuteSanScript method allows overcoming of that limitation. The piece of sanScript code pre-written or dynamically generated could be passed-in to Microsoft Dynamics GP runtime engine, and compiled and executed on-the-fly with immediate effect.
Documentation
Microsoft Dynamics Great Plains Continuum sanScript Supplement (http://mbs.microsoft.com/downloads/public/GP90Docs/SanScriptSupplement.pdf) and sanScript Reference (http://mbs.microsoft.com/downloads/public/GP90Docs/Sanscrpt.pdf) should be the main source of information. Those documents contain description of sanScript language, rules for syntax and statements, functions/operators reference, and code examples.
Continuum / sanScript code examples
1) Exchange parameters between the external application and sanScript engine
Class ParamHandlerClass
Public Value1 As String
Public Value2 As String
End Class
Set ParamHandler = new ParamHandlerClass
Set GPApp = GetObject("", "Dynamics.Application")
Set ParamHandler = New ParamHandlerClass
‘Assign ParamHandler as parameter exchange object
intRC = GPApp.SetParamHandler(ParamHandler)
‘Set value to pass in
ParamHandler.Value1 = “Test”
‘sanScript code to execute
sCode = "local string arg1; OLE_GetProperty(""Value1"", arg1);"
‘Execute
intRC = GPApp.ExecuteSanScript(sCode, sErrMsg)
‘intRC = 0 if execution successful, arg1 will contain the value passed in
‘otherwise intRC <> 0 and sErrMsg contains description of the error
2) Retrieve contents of a ComboBox
'Note.
'SanScript's string data type is limited up to 255 chars
'Therefore contents of the list is retrieved in a loop of calls
sListName = “’ (L) SQL_DataSource’ of window Login of form Login”
'Get list content count
sCode = "local integer count; count = countitems(" & sListName & "); OLE_SetProperty(""Value1"", str(count));"
intRC = GPApp.ExecuteSanScript(sCode, sErrMsg)
If intRC <> 0 Then
‘put your error handling here
End If
intCount = ParamHandler.Value1
If intCount = 0 Then
‘the list is empty, put your error handling here
End If
'Get first element
sCode = "OLE_SetProperty(""Value1"", itemname(" & sListName & ", 1));"
intRC = GPApp.ExecuteSanScript(sCode, sErrMsg)
If intRC <> 0 Then
‘put your error handling here
End If
sResult = ParamHandler.Value1
'Loop and retrieve the rest
For Iter = 2 To intCount
sCode = "OLE_SetProperty(""Value1"", itemname(" & sListName & ", " & Iter & "));"
intRC = GPApp.ExecuteSanScript(sCode, sErrMsg)
If intRC <> 0 Then
‘put your error handling here
End If
sResult = sResult & Chr(10) & ParamHandler.Value1
Next
VBScript limitation
ExecuteSanScript method uses “string pointer” for parameter exchange which is not supported in VBScript that has only and single “variant” data type. Passing in VBScript variables causes “Type Mismatch”.
The code samples given above were written in Visual Basic for Applications (VBA).
Excel.Application COM object was utilized as Automation Client.

