The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Run script when user logs in

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

I'm thinking of doing a few things when a user logs in.

So I'm looking into ways of how to trigger this. I found this Help the Helpdesk - run when logging into ServiceNow

which seems pretty straight forwards and isn't many line of code to get it to work.

So I created a global ui script to test, but I cant get it to work. can anyone explain why or have any other idea how to make something run when user logs on?

This is my code, pretty much copied from the above thread.

CustomEvent.observe('user.login', test);

function test() {

alert("CAN YOU FEEL IT!");

}

And nada happens.

1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

I found a way to do it.



When this inside a global ui script I get the "alert".



addLoadEvent( function() {


    if(window.frameElement){


          if(window.frameElement.id == 'gsft_main'){


                alert("Working?");


          }


    }


})


View solution in original post

10 REPLIES 10

Jamsta1912
Tera Guru

Hi Goran,



Depending on what you want your script to do, you could do this server side instead, by creating a business rule on the sys_user table, with condition last_login_time Changes, and putting your script there.


find_real_file.png


Jamie.


H Jamie,



You're right, I might need to say about what I'm wanting to do 😃



When user logs on, my script will check the user preferences, and if the correct value is there I think I will want a GlideDialogWindow will popup, haven't really decided what..



But for the sake of the case. Just lets say I want a popup window to show when user logs on =). If I can get this to work, I'll get the the rest later, but this is kind of a show stopper


Brian Dailey1
Kilo Sage

Hi Goran,



It's not very intuitive, but I think the place you need to look is called "Installation Exits".   There is a Login script in there that you can work with.



It's server-side, so you'll have to work out how you want to pass the values, maybe add to the client session data and then react to that with a client script somewhere of your choosing.



Good luck,


-Brian




Edit:   if you choose a business rule, I'd look at doing it on the sessions table at insert rather than on the user table.


Well, my problem is mainly how do I trigger it to happen "client side" directly after the user have logged in? how do I make a client script to hit on navpage.do?