Getting 'system' for gs.getUserID() in synchronous script action triggered by "session.established" event

sumitjumale
Kilo Contributor

Hi All,

I have created one synchronous script action which is getting triggered on "session.established" event.

I have written gs.getUserID() glide system function inside script action and printed with the help of log.

I am getting "system" instead of current user sys_id. Can anyone help me with this.

Regards,

Sumit

5 REPLIES 5

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

Can you explain what you mean by a synchronous script action?   As far as I'm aware all script actions will be asyncrhonous as the event will be queued and at some point in the future processed to fire the script action.   I suspect that is why you are getting the system user because the job executing the script action is being run by the system.



You can still get the user from the session.established event using event.parm1 (which is the user id).   If you need to get the sys id you can do something like:



var user = new GlideRecord('sys_user');


if (user.get('user_name',event.parm1)) {


      //do some stuff with user.sys_id


}


Would that work for your use case?


thanks for reply Joe.



"session.established" event is automatically triggered by system when user log into the system. So as per my understanding there is no scope of sending parameter like event.parm1.



Please find below link for more details.


http://wiki.servicenow.com/index.php?title=Session_Client_Data#gsc.tab=0


There should be as well as the IP in parm2.   There is even an OOB script action that uses event.parm1 with session.established.   And you can see the value of parm1 on the event log ('sysevent').   The event is triggered by the system, but it has a parameter and I didn't see any indication in your link to the Session Data page to the contrary.


Screen Shot 2017-02-21 at 9.37.42 AM.png


Screen Shot 2017-02-21 at 9.40.20 AM.png


Joe,



Could you please suggest me how to pass event.parm1 with current user name, so that I can retrieve it in script action.