Need help with a Event - Script Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2016 03:23 AM
Hi all,
i am trying to create a Event _ Script Action to get the current Users information .
The end goal of this effort to use the getClientData and putClientData in a Client Script and use this information to Hide a field if a User does not belong to a certain Country.
I am stuck already at the Script action to receive the current Users Sys ID
event name : session.established
Script :
myLoginAction();
function myLoginAction() {
var userID = gs.getUserID();
gs.log("UserID is : " + userID);
}
in the script log i see : UserID is : system
Any idea what i am doing wrong here ? It sounded so simple.
PS: Running Geneva Patch 4
thanks in advance
Frank
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2016 03:48 AM
Most probably the event is being fired by System, the Script action will always run in the context of the user.
You can go to scripts background and fire the event with gs.eventQueue() and see the output.
Please verify under whose context the event is being fired.
Mark if it is helpful or correct, feedback is appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2016 04:15 AM
Hi Frank,
Please pass gs.getUserID() as a parameter in gs.eventQueue() function you have written.
Suppose you have passed it in parameter 1. Then inside script action write
myLoginAction();
function myLoginAction() {
var userID = event.parm1;
gs.log("UserID is : " + userID);
}
Thanks,
Mihir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2016 04:23 AM
Hi Mihir,
i have not written a gs.eventQueue function.
i would like to use the event, session.established to save some variables for later actions based on the wiki:
Two ways to Reduce Client Side lookups
Instead of doing a client script for the computer table and each time a user is opening a record doing 2 glide calls, i thought it might be better for performance to use the getClientData and putClientData. In this way, i would just need 2 glide calls during the session.established and use the variables later on.
thanks
Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2016 05:44 AM
Frank,
You should be able to get the curent user's sys_id from a Script Action running on the session.established event. In order to do so, however, your Script Action has to set to run synchronously - as explained here: Session Client Data - ServiceNow Wiki
A better solution might be to check the user's credentials in a display Business Rule on the Computer table. Then, if the user is from the wrong country, you can pass the field names you need to hide on the client side - where you can easily iterate through them and hide them. Another solution is to check the user's country in the field-level read ACLs for the fields in question.
Thanks - and let me know if you have any other questions.