Customize User Login/Logout Information in Business Central – Part 2
We have basic information of user login/logout, you can refer to [Part 1] for details
Now we going to change the objects to have more information about user. The information including:
- Client Type
- Database Name
- Client Computer Name
- Server Instance Name
Summary about the customization.
- A new fields to table object.
- Populate new fields to list page object and user able to search this page in business central
- Change codeunit object to insert new field’s value into table
Table Object
table 57080 "User Entry Log"
{
Caption = 'User Entry Log';
DataClassification = EndUserIdentifiableInformation;
fields
{
field(1; "User ID"; Code[50])
{
Caption = 'User ID';
DataClassification = EndUserIdentifiableInformation;
NotBlank = true;
TableRelation = User."User Name";
ValidateTableRelation = false;
trigger OnValidate()
var
UserSelection: Codeunit "User Selection";
begin
UserSelection.ValidateUserName("User ID");
end;
}
field(2; "Login DateTime"; DateTime)
{
Caption = 'Login DateTime';
DataClassification = EndUserIdentifiableInformation;
}
field(3; "Logout DateTime"; DateTime)
{
Caption = 'Logout DateTime';
DataClassification = EndUserIdentifiableInformation;
}
// Part 2
field(4; "Client Type"; Text[50])
{
Caption = 'Client Type';
DataClassification = EndUserIdentifiableInformation;
}
field(5; "Database Name"; Text[250])
{
Caption = 'Database Name';
DataClassification = EndUserIdentifiableInformation;
}
field(6; "Client Computer Name"; Text[250])
{
Caption = 'Client Computer Name';
DataClassification = EndUserIdentifiableInformation;
}
field(7; "Server Instance Name"; Text[250])
{
Caption = 'Server Instance Name';
DataClassification = EndUserIdentifiableInformation;
}
// Part 2 -
}
keys
{
key(PK; "User ID", "Login DateTime")
{
Clustered = true;
}
}
}
List Page Object
page 57080 "User Entry Logs"
{
PageType = List;
ApplicationArea = All;
UsageCategory = Lists;
SourceTable = "User Entry Log";
InsertAllowed = false;
ModifyAllowed = false;
layout
{
area(Content)
{
repeater(GroupName)
{
field("User ID"; "User ID")
{
ApplicationArea = All;
}
field("Login DateTime"; "Login DateTime")
{
ApplicationArea = All;
}
field("Logout DateTime"; "Logout DateTime")
{
ApplicationArea = All;
}
// Part 2
field("Client Type"; "Client Type")
{
ApplicationArea = All;
}
field("Database Name"; "Database Name")
{
ApplicationArea = All;
}
field("Client Computer Name"; "Client Computer Name")
{
ApplicationArea = All;
}
field("Server Instance Name"; "Server Instance Name")
{
ApplicationArea = All;
}
// Part 2 -
}
}
}
}
Codeunit Object
codeunit 57080 "User Entry Management"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::LogInManagement, 'OnAfterLogInEnd', '', false, false)]
local procedure HandleOnAfterLogInEnd()
var
// Part 2
ActiveSession: Record "Active Session";
// Part 2 -
Session: Record Session;
UserEntryLog: Record "User Entry Log";
begin
if UserId = '' then begin
exit;
end;
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;
}
Details show in list page
*This post is locked for comments