web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / dK's Blog - BC/Nav / Customize User Login/Logout...

Customize User Login/Logout Information in Business Central – Part 3

Keck Chee Wey Profile Picture Keck Chee Wey

We have almost all available information of user login/logout, you can refer to [Part 1 and Part 2] for details

 

Now we going to adding control for user able to setup “who” to included login/logout information for system audit. In this blog, we going to extend standard business central “User Time Register” feature.

  1. Extend “General Ledger Setup” table to add new field “Activate User Entry Log”, this will be general setup for all user in business central
  2. Extend “User Setup” table to add new field “Activate User Entry Log”, this will control per user setup.
  3. Extend “General Ledger Setup” page and “User Setup” page to include new field create in point 1 and 2
  4. Modify “User Entry Management” codeunit to have new controls.

  

Table Extension: General Ledger Setup

// Part 3
tableextension 57080 "General Ledger Setup Ext" extends "General Ledger Setup"
{
    fields
    {
        Field(57080; "Activate User Entry Log"; Boolean)
        {
            Caption = 'Activate User Entry Log';
            DataClassification = EndUserIdentifiableInformation;
        }
    }
}

Table Extension: User Setup

// Part 3
tableextension 57081 "User Setup Ext" extends "User Setup"
{
    fields
    {
        Field(57080; "Activate User Entry Log"; Boolean)
        {
            Caption = 'Activate User Entry Log';
            DataClassification = EndUserIdentifiableInformation;
        }
    }
}

Page Extension: General Ledger Setup

// Part 3
pageextension 57080 "General Ledger Setup Ext" extends "General Ledger Setup"
{
    layout
    {
        addafter("Register Time")
        {
            field("Activate User Entry Log"; "Activate User Entry Log")
            {
                ApplicationArea = All;
            }
        }
    }
}

Page Extension: User Setup

// Part 3
pageextension 57081 "User Setup Ext" extends "User Setup"
{
    layout
    {
        addafter("Register Time")
        {
            field("Activate User Entry Log"; "Activate User Entry Log")
            {
                ApplicationArea = All;
            }
        }
    }
}

Codeunit object

codeunit 57080 "User Entry Management"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::LogInManagement, 'OnAfterLogInEnd', '', false, false)]
    local procedure HandleOnAfterLogInEnd()
    var
        // Part 3  
        GLSetup: Record "General Ledger Setup";
        UserSetup: Record "User Setup";
        ActivateUserEntryLog: Boolean;
        UserSetupFound: Boolean;
        // Part 3 -
        // Part 2  
        ActiveSession: Record "Active Session";
        // Part 2 -
        Session: Record Session;
        UserEntryLog: Record "User Entry Log";
    begin
        if UserId = '' then begin
            exit;
        end;

        // Part 3  
        if UserSetup.Get(UserId) then begin
            UserSetupFound := true;
            ActivateUserEntryLog := UserSetup."Activate User Entry Log";
        end;

        if not UserSetupFound then begin
            if GLSetup.Get() then begin
                ActivateUserEntryLog := GLSetup."Activate User Entry Log";
            end;
        end;

        if not ActivateUserEntryLog then begin
            exit;
        end;
        // Part 3 -

        Session.Reset();
        session.setrange("My Session", true);
        if session.FindFirst() then begin
            if session."User ID" = userid then begin
                // Part 2  
                ActiveSession.Reset();
                ActiveSession.SetRange("Session ID", Session."Connection ID");
                if not ActiveSession.FindFirst() then begin
                    ActiveSession.Init;
                end;
                // Part 2 -
                UserEntryLog.Init();
                UserEntryLog."User ID" := Session."User ID";
                UserEntryLog."Login DateTime" := CreateDateTime(Session."Login Date", Session."Login Time");
                UserEntryLog."Logout DateTime" := CurrentDateTime;
                // Part 2  
                UserEntryLog."Client Type" := Session."Application Name";
                UserEntryLog."Database Name" := Session."Database Name";
                UserEntryLog."Client Computer Name" := ActiveSession."Client Computer Name";
                UserEntryLog."Server Instance Name" := ActiveSession."Server Instance Name";
                // Part 2 -
                UserEntryLog.Insert;
            end;
        end;
    end;
}

New Setup column in General Ledger Setup Page

4666.pastedimage1596164011270v1.png

New Setup column in User Setup Page

2548.pastedimage1596164021485v2.png

Comments

*This post is locked for comments