Logon / login script - run once regardless of how I logon

poyntzj
Kilo Sage

I want to set some sessiondata for a feature I am working on, but I want to do this as the user logs on.   Most of our users are via SSO so I can work on that script, but there are the few exceptions - and on our DEV env where we using the internal credentials so I need to cover these too.

I have followed a couple of links, one on here and one from the SNCGuru

https://community.servicenow.com/message/873637#873637

http://www.servicenowguru.com/system-definition/login-terms-conditions-dialog/

and created a UI Script.

This is working, but it runs each time a page loads (I can tell from the debugging I was doing.)

I have put a check in place so that if the sessionData exists it will not reprocess it, but as I know this data on needs to be set the once I feel there must be somewhere better to put it.

I did look to run a rule based on the user session table but that did not seem to trigger when I was trying it

Any suggestions are appreciated

1 ACCEPTED SOLUTION

Frank1975
Kilo Guru

Hi Julian,


i was facing the same issue 2 weeks ago and i worked with the



Session Client Data - ServiceNow Wiki



During the session.established event (i created an Action Script) i put the users Location and Country into the getClientData and later using this in a Client Script putClientData. So instead of each time doing a glide record, i am doing just 1 when the user log on.



Hope this helps , let me know if you have any questions



Frank


View solution in original post

4 REPLIES 4

Frank1975
Kilo Guru

Hi Julian,


i was facing the same issue 2 weeks ago and i worked with the



Session Client Data - ServiceNow Wiki



During the session.established event (i created an Action Script) i put the users Location and Country into the getClientData and later using this in a Client Script putClientData. So instead of each time doing a glide record, i am doing just 1 when the user log on.



Hope this helps , let me know if you have any questions



Frank


poyntzj
Kilo Sage

Creating a new script was causing an issue as it always reported it was running as system and the roles were admin


In the end I inserted a copy of the SetTheme version, changed what I wanted there and it is now working



Happy days


Daniel Draes
ServiceNow Employee
ServiceNow Employee

Clever trick!



Bottom line is that the script actions usually run asynchronously'. This way the session return to the user without the information in your script.


By copying the 'Set Theme' you picked on that is marked as synchron operation. The field for this is hidden by ACL. So far I have always mocked with the ACL to make the field visible. But this is so much more elegant


that will explain it.:)