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

I did try my script. But it doesn't work. ðŸ˜¥

The gs.addInfoMessage() function fails when triggered during logon. Instead of adding the message to the next window loaded, it does nothing.

if (previous.last_login_time) {
	gs.addInfoMessage('Welcome ' + gs.getUserDisplayName()
		+ ', your last login was on ' + previous.last_login_time.getDisplayValue()
		+ ' (from ' + previous.last_login_device + ')'
		+ '<br/>If this was not you, please inform IT Security immediately.'
	);
}

Since a UI based solution is not available, we could use another output, like triggering an email notification by registering an event.

 

One misunderstanding I had was that the "last_login_time" was most recent previous login.  It is actually set when you logged in for your current session.

So I created another field, "previous_login_time" and created a Business Rule that is fired off when "last_login_time" changes (whenever you log in).

 

(function executeRule(current, previous /*null when async*/)
{
current.u_previous_login_time = previous.last_login_time;
}
)(current, previous);

With that in place, I've tried various modifications to your code.  I'm not getting an error, but I'm also not getting a message showing up either.

(function executeRule(current, previous /*null when async*/)
{
gs.addInfoMessage("Your last login was on " + current.u_previous_login_time);
}
)(current, previous);

Michael Richard
Tera Contributor

Thank you.   That looks exactly like what I'm looking for.

 

Where would be the best place to study up on creating advanced business rules?

Hi Michael!

The developer website would be the obvious place to learn how to create advanced business rules.