How to show last logged on time when user logs on.

Michael Richard
Tera Contributor

Is there an existing method, property or widget that shows a user their last logged on time when they first log in?

1 ACCEPTED SOLUTION

Hey Michael - got it..   That would actually be a cool widget 🙂

I'm not aware of something that already exists to show the interactively logged on user this data when they login.

Might want to look at a report that you can stick onto a Homepage or Dashboard.

  • Would need to do some testing and ACL permission checking but potentially could create a report like:
    • Table = [sys_user]
    • Condition = [sys_id = javascript:gs.getUserID();]

I suspect folks in the Platform Community may have a more elegant solution that this, but it's a starting point to investigate...

 

find_real_file.png

View solution in original post

8 REPLIES 8

andy_ojha
ServiceNow Employee
ServiceNow Employee

Hey Michael - you can spot this information on the <sys_user> table, there is a field on 'Last login time'.

Noticing that you posted this in the Security Operations (SecOps) Community - this question might be more appropriate for the Platform Community.  The SecOps Community is more tailored to the SecOps suite of ServiceNow Applications.

Reference:

find_real_file.png

Michael Richard
Tera Contributor

Thanks.    I'll take this to the Platform community.  I did see that field in the data.   I'm just trying to get that information to be available as the user logs in.

Hey Michael - got it..   That would actually be a cool widget 🙂

I'm not aware of something that already exists to show the interactively logged on user this data when they login.

Might want to look at a report that you can stick onto a Homepage or Dashboard.

  • Would need to do some testing and ACL permission checking but potentially could create a report like:
    • Table = [sys_user]
    • Condition = [sys_id = javascript:gs.getUserID();]

I suspect folks in the Platform Community may have a more elegant solution that this, but it's a starting point to investigate...

 

find_real_file.png

Shiva Thomas
Kilo Sage

Hi Michael,

Keep in mind that the Last Login Time field is only updated when you log. Not when you connect.

If you logged for the first time a month ago, then connected every few day without having to re-enter your password, because your browser session was still valid, then the Last login time would be last month.
This is the last time you had to enter your password.

It could potentially lower the value of such a security welcome banner.
If this is still valuable to you, then I would create an advanced business rule (on update) for the sys_user table, triggered each time the last login time is updated.

The script would then contain something like:

If (previous.last_login_date)
    gs.addInfoMessage(“Welcome “ + gs.getCurrentUser().getDisplayValue() + “, your last login was on “ + previous.last_login_date.getDisplayValue());

(Script not tested, as I’m writing from my mobile phone, but I can complete it if required)

That would ensure that the security banner is displayed after every login, regardless of the page opened.


Best regards from Switzerland
Shiva :¬,

If this reply assisted you, please consider marking it 👍Helpful or Correct.
This enables other customers to learn from your thread.