This is the second in a series of posts which are are designed to help Dexterity developers as well as VBA and Visual Studio Developers to understand how to work with passthrough Dexterity sanScript. The main focus of this series is to understand how to change the Dictionary Context that the code executes in.
If you have not read the first post, please do so now to get the background for this post.
Disclaimer: The method of calling passthrough sanScript from VBA is not supported by Microsoft. However as it is such a useful technique, you will see it used may times on this blog.
The methods used here show the script examples using VBA. The concept can easily transferred over to VB.Net and C# in Visual Studio.
The first script example uses the same Dexterity sanScript code to display the Product ID and Name for the dictionary context. This shows the standard method of calling sanScript from VBA using the ExecuteSanscript method in the Dynamics.Application object. The context for this script is controlled by the CurrentProductID property.
Note: The double quotes in the sanScript code have to be doubled up to ensure the double quote character is included in the vba string variable.
VBA Code Example showing simple passthrough Dexterity sanScript
‘ Create link without having reference marked
Set CompilerApp = CreateObject(“Dynamics.Application”)
CompilerCommand = “”
CompilerCommand = CompilerCommand & “warning “”Product Context is “” ” & vbCrLf
CompilerCommand = CompilerCommand & ” + str(Runtime_GetCurrentProductID()) + “”: “” ” & vbCrLf
CompilerCommand = CompilerCommand & ” + Launch_GetProdName(Runtime_GetCurrentProductID()); ” & vbCrLf
‘ Execute SanScript
CompilerApp.CurrentProductID = 1493 ‘ SmartList
‘CompilerApp.CurrentProduct = CompilerApp.CurrentProduct & “!Modified”
CompilerError = CompilerApp.ExecuteSanscript(CompilerCommand, CompilerMessage)
If CompilerError <> 0 Then
Note: The code using late binding to the Dynamics.Appliction object. This avoids the need to create a reference to the Continuum Integration Library. Also note the commented out line which can be used to change the context to allow the passthrough code to work with the modified version of a window.
The second example uses Dexterity’s execute() function to change the context from the context defined at the VBA level to another context. This method can be used when there are issues getting the VBA context selection to work. The double quotes have to be double up again for the extra level of nesting.
Following on from the previous post, this next script is just to create the Dexterity sanScript code in a text file. You can use any method you wish to write the code and place it into a text file.
This final example uses passthrough Dexterity sanScript to read the previously created text file and execute the code in the specified context.
Using this two stage method of writing to a text file and then reading the file and executing the code has the advantage that the code is a little simpler to write because we don’t have the quadruple double quotes that the second example on this post has.
Note: Please see the previous post for a discussion of generic and native pathnames.
Please let me know if these techniques are useful to you.
// Copyright © Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)