Creating a Support Debugging Tool Non-Logging Trigger to run after login

David Meego - Click for blog homepageThis is a reposting of an article I originally wrote on my Developing for Dynamics GP blog.

This little hint might be handy if you are trying to use the Support Debugging Tool to create a non-logging trigger to run some code after a user logs in.

The Support Debugging Tool uses a trigger after the Add_Successful_Login_Record global procedure (see more information below) to start its initialization after a user has logged in. Part of this process is starting triggers marked to Automatically Start on Login.

So the question is: What event can I trigger on that happens AFTER the triggers are initialized so that I can run my SDT created trigger when a user logs in?

Well, I had to answer this question myself recently as I wanted to run some code to compare the SQL User ID used to log into Microsoft Dynamics GP with the Windows User ID currently in use on the machine. The site in question created the SQL User IDs to match the Windows User IDs and this script was meant to detect when users logged into Microsoft Dynamics using a different Dynamics User ID to their Windows User ID.

The solution is use a procedure trigger on the global procedure SQM_StartForApp. This procedure is called just after the Add_Successful_Login_Record global procedure.

Below is the script I used for the User ID example. This runs as a non-logging trigger in the context of the Microsoft Dynamics GP dictionary:
Conditional Script Example

out boolean OUT_Condition;

local string compiler_error;
local string l_user;

OUT_Condition = false;

if execute(5261, "inout string INOUT_User; INOUT_User = GetUserName();", compiler_error, l_user) <> 0 then
  {A compiler error occurred. Display the error.}
  error compiler_error;
end if;
if l_user <> 'User ID' of globals then { Insert Condition Here }
  call with name "MBS_Auto_Log" in dictionary 5261, "Windows User: " + l_user + " SQL User: " + 'User ID' of globals;
  OUT_Condition = true;
end if;

NOTE: This code obtains the Windows User ID by calling the GetUserName() function in the Support Debugging Tool dictionary (5261) using some passthrough sanScript and the execute() function.

You can also import the Debugger Settings Login Check.dbg.xml Support Debugging Tool Configuration Settings file which is attached to the bottom of this post.

For more information see

Hope this is useful.

David

// 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.)

Debugger Settings Login Check.dbg.zip

This article was originally posted on the Developing for Dynamics GP Blog and has been reposted on http://www.winthropdc.com/blog.

2 thoughts on “Creating a Support Debugging Tool Non-Logging Trigger to run after login

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.