- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 08-20-2021 08:33 AM
From time to time at Community the question arises how to track when which users have logged in via Service Portal or via Backend.
In order not have to implement a new application for this purpose, it would make sense using one of the OOTB tables. The table sysevent (Event Log) is a promising candidate:
We can see who has logged in when. But we cannot see where the user has logged in.
To answer this question we need the syslog_transaction table (Transaction Log), which stores records regarding all browser activities for an instance. The session value of that table corresponds to the instance field at table sysevent. To distinguish where a user has logged in, you can look for a value in the URL field that starts with "/api/now/sp":
Now you only need an Action Script that listens for the "login" event and writes into the field parm2 whether the user has logged in to the "Backend" or to the "Portal":
For better copying, find the following code from field "Script":
var grTransactionLog = new GlideRecord('syslog_transaction');
grTransactionLog.addEncodedQuery('urlSTARTSWITH/api/now/sp^session=' + event.getValue('instance'));
grTransactionLog.setLimit(1);
grTransactionLog.query();
event.setValue('parm2', grTransactionLog.next() ? 'Portal' : 'Backend');
event.update();
Now at table sysevent you have everything you need for generating the required reports:
Please note
With my solution, the IP address of the logged-in user (value of "Parm2" field at table sysevent) is overridden. If you need that IP address for tracking purposes you also can add a new custom field to that table and store the login source there.
All records older than 7 days are cleared automatically by the OOTB table cleaner. To increase the value of 604800 seconds go to table sys_auto_flush and search for table "sysevent". Then enter a respective value at column "Age in seconds":
- 6,584 Views


- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
Thanks for the article.
I do want to say that this does overwrite the IP address that by default is captured in the parm2 field and that some may want to retain that for security purposes, etc. (I know I would).
Perhaps it could be appended to that field and still retain the IP value or place it in another field, if applicable.
Just a thought.
Please mark reply as Helpful, if applicable. Thanks!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi
thanks for the hint and yes you are completely right. As I wanted a quick uncomplicated approach for a asking user the deleted IP address is the "collateral damage" on this solution. Another option I can image is inserting an additional field "login source".
Kind regards
Maik


- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
Great. Glad it was helpful. You may want to add that to your article either way so that it's completely transparent to readers.
Thanks
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes, in any case I will do that in the next few days, because the article needs some "polish" moreover.