“How -to” restrict multiple logins for same user in NAV

Force logins limitations for some users can boost\improve system (few active Sessions..) as standard users can login in NAV multiple times, ex of real Scenario: CEO can have multiple logins, operational people NO !!

 NAV 2013 and Later

From NAV 2013 Microsoft created a table named: Active Sessions – Table ID 2000000110 This table contains information about all the active sessions, showing Connected Client Type\PC and Users)

Take a look to my previous post about “ALL ABOUT” Kill (In)active Sessions when “no more licenses”, with the VB.NET app in this post, you can show Client Type\PC and Connected User from this app to decide “who is the user” than try to use more than one NAV session.

Source https://robertostefanettinavblog.wordpress.com/2017/01/15/all-about-kill-inactive-sessions-when-no-more-licenses/


Starting from User Setup Table

You can add a boolean field “Multilogin” to User Setup Table (table 91)” ; with this boolean field you can check if user can login more times in NAV instead of only one time.

User Setup – Table ID 91 User Setup

ml-1

Before you need to add the new field “Multilogin” on Page “User Setup” (…or comment C/AL check code… you can’t login in anyway if you haven’t configured your user in this table)

..We can’t use System Table User.. because is used by System on Login process .. if you try to use this table you can’t start Windows Client…

ml-2

ml 3.png

To Restrict multiple logins we can use Login Codeunit

Codeunit 40 – LogInManagement

This codeunit is ht first fired on Login Time and I can add C/AL code here to trap user logins.
Steps: Open Codeunit 40, goto function CompanyOpen()

In CompanyOpen function add two new local variables: locUser and locActiveSessione

ml-4

Modify the CompanyOpen function in this way:

C/AL Code “Before” 

CompanyOpen()

IF GUIALLOWED THEN   LogInStart; C/AL Code “After”

CompanyOpen()

locUser.GET(UPPERCASE(USERID));

IF NOT locUser.Multilogin THEN

BEGIN

locActiveSession.RESET;

locActiveSession.SETRANGE(“User ID”,UPPERCASE(USERID));

locActiveSession.SETRANGE(“Client Type”, locActiveSession.”Client Type”::”Windows Client”); //For   RTC\Windows Clients

IF locActiveSession.COUNT > 1 THEN

ERROR(‘You are currently logged in NAV, you can’t have more sessions!’);

END;

IF GUIALLOWED THEN

LogInStart;

// Register all Microsoft Dynamics CRM connection strings

IF CRMConnectionSetup.GET THEN

CRMConnectionSetup.UpdateAllConnectionRegistrations;

Results

System abort login codeunit and display the Error Message “’You are currently logged in NAV, you can’t have more sessions!”; you can use\trap also others login types: ex: Web Client, Web Service, Background Sessions and so on.

ml 5.png

Another Nice Feature

You can decide also “how many sessions” each user can launch adding a “No. Sessions” field in User Table.

 ml-6

C/AL Code

CompanyOpen()

locUser.GET(UPPERCASE(USERID));

IF NOT locUser.Multilogin THEN

BEGIN

locActiveSession.RESET;

locActiveSession.SETRANGE(“User ID”,UPPERCASE(USERID));

locActiveSession.SETRANGE(“Client Type”, locActiveSession.”Client Type”::”Windows Client”); //For   RTC\Windows Clients

IF locActiveSession.COUNT > 1 THEN

ERROR(‘You are currently logged in NAV, you can’t have more sessions!’);

END

ELSE

BEGIN

locActiveSession.RESET;

locActiveSession.SETRANGE(“User ID”,UPPERCASE(USERID));

locActiveSession.SETRANGE(“Client Type”, locActiveSession.”Client Type”::”Windows Client”); //For   RTC\Windows Clients

IF locActiveSession.COUNT > locUser.”No. Sessions” THEN

ERROR(‘You are currently logged in NAV, you can’t have more than ‘ + FORMAT(locActiveSession.COUNT-1) + ‘ sessions!’);

END;

IF GUIALLOWED THEN

LogInStart;

// Register all Microsoft Dynamics CRM connection strings

IF CRMConnectionSetup.GET THEN

CRMConnectionSetup.UpdateAllConnectionRegistrations;

Results

ml-7

Bingo !

2 thoughts on ““How -to” restrict multiple logins for same user in NAV

  • 1 February 2017 at 3:54 PM
    Permalink

    Isn’t this irrelevant now. My understanding is that actually if a user opens up more sessions only 1 license seat is taken for that user. This is the case as long as it isn’t a subscription (SAL) based license. For a perpetual license you do not get this problem as the user can open as many sessions as they like and actually only uses up one seat on the license. This was a change made by Microsoft some time ago.

    Reply
    • 1 February 2017 at 4:03 PM
      Permalink

      you are right… sure… but fixed only from NAV 2013 CU 5 (confirmed by Microsoft from my old support ticket….counter doesn’t work fine..) .. if you have older version and customer doesn’t want to upgrade you can have license issues….. but this utility is useful to have better performance…for example one user crate a new nav session when push “export to Excel”…

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

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