Restrict non-admin users to open multiple sessions in AX

Restrict non-admin users to open multiple sessions in AX

MCP · Azure DevOpsYour delivery board, readable by an agentMCP · DataverseOne consent, and the data layer opensMCP · Dynamics 365 F&OConnecting F&O to an agent Microsoft hasn’t documented
Few times client asked to restrict their users to not open AX sessions multiple times. As It may impact on performance somehow. The following code snipet can do this job for you.

NOTE: Please take backup of your application before copying code

Copy Paste the Following Code in startupPost method of info class in AOT

void startupPost()
{
   // To restrict user login form second login
   xSession session;
   SysClientSessions SysClientSessions;
   UserId currentUserId;
   int counter;


   currentUserId = curUserId();

   if(currentUserId!="Admin")// Allow Admin User to login multiple time
   {
      while select SysClientSessions
         where SysClientSessions.userId == currentUserId
         &&     SysClientSessions.Status == 1 // 1 : Login 0 : Logout
      {
         session = new xSession(SysClientSessions.SessionId, true);
         if (session && session.userId())
         {
            counter++;
         }
      }

      if (counter >= 2)
      {
         Box::stop("Already Logged-in : The same user id can't log in twice.");
         infolog.shutDown(true);
      }
   }
}
Previous article← AX 2012 - Compile and CIL Generation errors
Discussion

Ask a question or leave feedback

This is a review interaction. The WordPress version will store, thread and moderate comments.

Thanks — submitted for moderation in this review.
Search the whole site · Ctrl/⌘ + K