How can I execute a Dexterity procedure programmatically?
Goal:
I want to reset a user password within GP 2018 programmatically. For the purposes of any discussion we have moving forward, programmatically does NOT refer to the following:
- Clicking buttons in a user interface manually, particularly after launching Dynamics.exe
- Running a Great Plains 2018 macro
Background:
- The only possible supported solution for what I am trying to achieve I believe must rely on Dexterity. I have no idea how to execute a Dexterity procedure programmatically, so this might be impossible.
- I have a Dexterity script (Dynamics procedure) defined which is very simple—it resets a GP user password via Login_AlterLogin(). It has no parameters and is based on the examples provided in Dex.chm help file.
- To deploy and use this Dexterity script I have done the following:
- Created a dictionary (dev.dic)
- Created and compiled the Dexterity script within my editable dictionary (dev.dic)
- Created a CNK file (dev.cnk)
- Launched GP and performed unchunking
- Generated a DLL using Dag.exe (Application.Dev.dll)
- Adding the assembly into my Visual Studio project (Application.Dev assembly added to a C# console app)
- Attempted to Invoke the procedure (Dexterity.Applications.Dev.Procedures.Dev.Invoke();).
- My C# app attempts to make a GP connection before invoking the procedure, as shown below.
- I have validated that my GPConnection is successfully connecting (gpConn.ReturnCode = 1).
Code (C#):
SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = string.Format("Database = {0}", "RST");
int resp = GPConnection.Startup();
GPConnection gpConn = new GPConnection();
gpConn.Init("CompanyName", "1233_special_keys_for_vstools_5678");
gpConn.Connect(sqlConn, "DEV1", "sa", "Secret_pwd678");
Microsoft.Dexterity.Applications.Dev.Procedures.Dev.Invoke();
resp = GPConnection.Shutdown();
Error:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'Microsoft.Dexterity.Applications.root' threw an exception.
Source=Application.Dev
StackTrace:
at Microsoft.Dexterity.Applications.DevDictionary.DevProcedure.get_WrappedScript()
at Microsoft.Dexterity.Applications.DevDictionary.DevProcedure.Invoke()
at gp_test.Program.MakeConnection() in C:\Users\administrator.ROCKSOLID\source\repos\gp_test\gp_test\Program.cs:line 27
at gp_test.Program.Main(String[] args) in C:\Users\administrator.ROCKSOLID\source\repos\gp_test\gp_test\Program.cs:line 11
Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.