Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Hi Goran - thanks for getting back with me.   I was able to make it work as follows:


addLoadEvent( function() {


    if(!g_user.hasRole("admin") && g_user.hasRole("itil") && window.frameElement && window.frameElement.id == 'gsft_main'){


          if (window.frameElement.src.indexOf('welcome.do') > 0){


  alert("YUUUP");


          }


    }


});


for some reason, the extra role check prevents it from popping up on logOUT as well...not sure why.



I still wish I could find a way to do this with a Installation Exit..absolutely no luck with that.