Customize User Login/Logout Information in Business Central – Part 3
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.
- Extend “General Ledger Setup” table to add new field “Activate User Entry Log”, this will be general setup for all user in business central
- Extend “User Setup” table to add new field “Activate User Entry Log”, this will control per user setup.
- Extend “General Ledger Setup” page and “User Setup” page to include new field create in point 1 and 2
- 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
New Setup column in User Setup Page

Like
Report
*This post is locked for comments