Dynamics 365 Business Central: How to list currently logged in users (Sessions)

Dynamics 365 Business Central

Hi, Readers.
A few days ago I was asked a question, how to list currently logged-in users in Business Central.
So in this post, I will briefly summarize and hope to help you.
The keyword this time is Sessions.

Managing Sessions in the Admin Center (SaaS)

For each environment in the Business Central administration center, you can use the Manage Sessions page to view information about active sessions on an environment and cancel selected sessions.

To open the page, choose the environment you want to manage.

Then select Sessions.

There are currently four users logged in.

You can use the Show session details check box to show more or fewer details.

Note: One user can have multiple sessions at the same time.

PS:
1. You can select the sessions and then choose Cancel selected sessions to cancel sessions.

Canceling a session is sometimes the only way to unblock a customer. For example, a long-running report is locking data in a table, preventing warehouse employees from working.

2. The following users are authorized to access the Business Central administration center:

  • Internal tenant administrators
  • Admin agent
  • Helpdesk agent

Internal administrators are users who are assigned the Global admin role or the Dynamics 365 Admin role in the Microsoft 365 admin center. These users are typically system administrators, IT professionals, or super users at the customer’s company. For more information, see About admin roles in the Microsoft 365 admin content.

The admin agent and helpdesk agent roles are assigned through the Microsoft Partner Center for the partner that is associated with the tenant. These roles can access the Business Central tenant as delegated administrators. For more information, see Administration of Business Central Online.

Using system table 2000000110 Active Session (SaaS and On-Pre)

You can force Business Central to run the “Active Session” table by adding the ?table=2000000110 parameter to the URL, such as in the following example: 
https://businesscentral.dynamics.com/d8f36038-1f93-4543-affc-5dc92b6ee871/Sandbox?table=2000000110

There are currently four users logged in.

Note: Like in the Admin Center, one user can have multiple sessions at the same time.

We can do a little customization, create a new page and pick the fields we need.

Test Video:

Source Code: For reference only

page 50100 "ZY Logged In Users"
{
    ApplicationArea = All;
    Caption = 'Currently Logged In Users';
    PageType = List;
    SourceTable = "Active Session";
    SourceTableTemporary = true;
    UsageCategory = Lists;
    InsertAllowed = false;
    Editable = false;
    DeleteAllowed = false;

    layout
    {
        area(content)
        {
            repeater(General)
            {
                field("User ID"; Rec."User ID")
                {
                    ToolTip = 'Specifies the value of the User ID field';
                    ApplicationArea = All;
                }
                field("Login Datetime"; Rec."Login Datetime")
                {
                    ToolTip = 'Specifies the value of the Login Datetime field';
                    ApplicationArea = All;
                }
                field("Client Type"; Rec."Client Type")
                {
                    ToolTip = 'Specifies the value of the Client Type field';
                    ApplicationArea = All;
                }
            }
        }
    }

    trigger OnOpenPage()
    var
        ActiveSession: Record "Active Session";
        LastUserID: Text[132];
    begin
        LastUserID := '';
        ActiveSession.Reset();
        ActiveSession.SetCurrentKey("User ID");
        ActiveSession.Ascending(true);
        if ActiveSession.FindSet() then
            repeat
                if not (ActiveSession."User ID" = LastUserID) then begin
                    Rec.Init();
                    Rec."Server Instance ID" := ActiveSession."Server Instance ID";
                    Rec."Session ID" := ActiveSession."Session ID";
                    Rec."User ID" := ActiveSession."User ID";
                    Rec."Login Datetime" := ActiveSession."Login Datetime";
                    Rec."Client Type" := ActiveSession."Client Type";
                    Rec.Insert();
                    LastUserID := ActiveSession."User ID";
                end;
            until ActiveSession.Next() = 0;
    end;
}

On-Premises:

PS: You can add this page to Web Services, and access the data by Odata at any time.

Using Get-NAVServerSession command (On-Pre)

Get-NAVServerSession: Returns information about active sessions for a Business Central Server instance.

For example: Get-NAVServerSession -ServerInstance BC183 -Tenant default

In fact, you can also use Application Insights to see the currently logged-in users and the sessions, but you cannot see the exact details.
More details: How to Send telemetry to Microsoft Azure Application Insights

END

Hope this will help.

Thanks for reading.

ZHU

コメント

タイトルとURLをコピーしました