Table "Session Event" - OnAfterInsertEvent never fired?

MarHan
Member Posts: 34
Hey guys,
has anyone of you ever managed to subscribe successfully to the "OnAfterInsertEvent" of Table "Session Event"?
I'm doing this:
[EventSubscriber(ObjectType::Table, Database::"Session Event", 'OnAfterInsertEvent', '', false, false)]
local procedure User_Session_Event_Inserted_Handler(var Rec: Record "Session Event")
begin
if Rec."Client Type" <> Rec."Client Type"::"Web Client" then
exit;
// Do some stuff here when a User logged in via Modern Client
end;
But neither my breakpoints are hit inside that handler nor my debugging textfile gets written. Am a bit confused now.
Regards
Markus
has anyone of you ever managed to subscribe successfully to the "OnAfterInsertEvent" of Table "Session Event"?
I'm doing this:
[EventSubscriber(ObjectType::Table, Database::"Session Event", 'OnAfterInsertEvent', '', false, false)]
local procedure User_Session_Event_Inserted_Handler(var Rec: Record "Session Event")
begin
if Rec."Client Type" <> Rec."Client Type"::"Web Client" then
exit;
// Do some stuff here when a User logged in via Modern Client
end;
But neither my breakpoints are hit inside that handler nor my debugging textfile gets written. Am a bit confused now.
Regards
Markus
0
Answers
-
Is this Onprem version of BC?United Kingdom0
-
Developer101 wrote: »Is this Onprem version of BC?
Yes it is, running in a dev container, build from BC container helper.
I also fiddled a bit around with
- table 2000000110 "Active Session" > OnAfterInsertEvent: Seems to works neither
- codeunit 40 LogInManagement > OnAfterLogInEnd: Seems to be deprecated
- codeunit 150 "System Initialization" > OnAfterLogin: No information about the user
Could it be that some of the session related stuff is done in "a deeper layer" somehow between SQL and BC server and not in that place where other events get fired?0 -
What is requirement here? What is an end goal?United Kingdom0
-
As shown in my code: // Do some stuff here when a User logged in via Modern Client
I want to log a users last logon and logoff timestamps in my app for example.0 -
Why not use standard functionality? When "Register Time" is enabled on User Setup, a record is created in "User Time Register" when they first log in on a given day. The record is also updated with the number of minutes they are online. For each day, you can track $SystemCreatedAt and last $SystemModifiedAt.
You're not going to get anywhere (good) trying to subsribe directly to a system table.
As an alternative, you can use Codeunit 40 LogInManagement's event OnAfterCompanyOpen to get login events.0 -
Thanks for your advice, but the time register stuff must be explicitly activated and I cannot go for sure that it is. Codeunits 40's "OnAfterCompanyOpen" is marked for removal with 20.0. We're currently merging in BC21.4 so could be not the best idea to build new stuff on that now.0
-
When an event, function, table, etc. is marked for removal, in most cases Microsoft includes pointer to a replacement object:
[Obsolete('Replaced with OnAfterLogin in codeunit "System Initialization"', '20.0')] [IntegrationEvent(false, false)] local procedure OnBeforeCompanyOpen() begin end;
0 -
The "OnAfterLogin" event in "codeunit 150 System Initialization" unfortunately does not provide access or information about the user that currently has logged in. It seems only to be a "neutral" hook to add your own initialization stuff after the login. Or am I missunderstanding something?0
-
You can always get current user with built-in system function UserID() or UserSecurityID(), depending on which one you need.1
-
*Ashamed* you're so right - I totally forgot about those system functions 🙈. I managed to subscribe to the "OnAfterLogin"-Event of codeunit "System Initialization". Do you know something similar for logoff? Because I also need the timestamp when a user has finished his work and is no longer active inside the system.0
-
Users typically don't actively sign off, and when they just close the browser, the session remains open for a little while. Depending on how things go, even Active Session record might remain even if the session itself is gone. Your best bet would be to enable Time Registers and treat modifications to it as "Last interaction" or something0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions