Friday, February 20, 2009

Reset GP after Integration Manager error

Integration Manager is a useful tool for certain situations, but if you've used it enough, you know that it has a few annoying quirks.

In order for IM to run integrations, Dynamics GP must be running. While the integration runs, IM hides the main GP window, and then executes its macros. When the integration is complete, it un-hides GP. This usually works fine, but there are cases where IM will have an error, causing the integration to fail or stop. Sometimes when this happens, IM will not un-hide GP. This can get pretty annoying after a few times when you are debugging an integration.

Even though you can't see GP, the Dynamics.exe process stays running, so you have to kill that process. But then your login is still sitting in the ACTIVITY table, so you have to delete that the next time you login. If this happens rarely, no big deal, but while testing an integration recently, I had some errors that caused the integration to fail, and left GP hidden every single time. After the 10th time of resetting GP, I finally decided to honor MacGyver and find a better solution.

While testing my integration, if an IM error occurred, I wanted to automatically:

1) Get rid of the orphaned Dynamics.exe process
2) Clear my orphaned GP login
3) While I'm at it, why not just log me back into GP?

I created this solution for use on my development servers--where both SQL Server and GP are installed locally, and I'm working directly on the server logged in as a Windows Administrator. I'm also just using the TWO / Fabrikam company. With a little additional effort, you could make this work on a standard GP workstation as well.

Here are the steps to "Reset GP":

Modify your Windows PATH environment variable to include the Dynamics GP application directory (i.e. add C:\Program Files\Microsoft Dynamics\GP\ to the end)



Reboot the machine so that the new PATH is loaded (you can test this by clicking Start-->Run-->Type Dynamics.exe and click OK)
Download the PS Kill utility from the MS Sysinternals site
Extract the pskill.exe file to C:\, or some other directory that you know is in the PATH (i.e. C:\Windows)

In Notepad, click on File and then New

Copy and paste the following text:

pskill dynamics.exe
sqlcmd -S sqlserver\GP10 -E -Q "DELETE FROM DYNAMICS.dbo.ACTIVITY WHERE USERID = 'sa'"
start Dynamics.exe Dynamics.set login.mac

Make sure to change the name of the SQL server and instance to match your installation. Also, this script uses Windows Authentication for SQL Server, assuming you are running as an Administrator. You can add the -U and -P parameters if you wish to specify a SQL username and password.

Save the file as C:\ResetGP.bat

In Notepad, click on File and New

Copy and paste the following text into the new Notepad file:

Logging file 'none.txt'
CheckActiveWin dictionary 'default' form Login window Login
TypeTo field 'User ID' , 'sa'
MoveTo field Password
TypeTo field Password , 'password'
CheckActiveWin dictionary 'default' form Login window Login
MoveTo field 'OK Button'
ClickHit field 'OK Button'
NewActiveWin dictionary 'default' form 'Switch Company' window 'Switch Company'
ClickHit field '(L) Company Names' item 1 # 'The World Online, Inc.'
MoveTo field 'OK Button'
ClickHit field 'OK Button'


Save the file as "login.mac" in your Dynamics GP application directory.

Now, create a shortcut on your desktop that points to the C:\ResetGP.bat file.

Viola! You can now reset GP by double clicking on an icon. You can even put the icon in your Quick Launch toolbar and make it a single click.

No comments: