Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
marcguy
ServiceNow Employee
ServiceNow Employee

Have you found yourself frequently writing the same client scripts, glideAjax calls and Script Includes to access certain data about the current user? i.e. which groups they belong to, which roles they have in those groups, their country/location/manager etc.

 

Well, if you do access the same data frequently, or find it hard to write particular client side scripts to capture this data, there is a method to actually set and store the client session data, then access it on demand in the client with one line. So I thought I would give a couple of practical examples where this can come in handy and help reduce those glideAjax calls even when they are running server side, asynchronously etc.

 

The first thing you need to decide is which data would be useful to you in your client scripts. Once you know what is useful, you can create a Script Action to run on the event 'session.established' (i.e. when a user logs in).

 

Here are two examples of how you can reduce client side lookups.

 

Capture the groups the user belongs to plus a few other useful items that you can use later

 

Script Action.png

 

So we now have this data being collected on login (note: this data is only collected once, so if a user changes groups or any other data, the data will still be the login data).

 

Now, how do we access this data? Well, it's just one line of code:

 

var myGrps = g_user.getClientData('u_userGroupList');

 

It is a lot quicker than writing glideAjax to return users groups right?

 


Use a client script to check if the current user is a member of the assignment group and prompt them be assigned to an incident

 

Client Script.png

 

I'm sure you can find many more uses for this method but checking for the groups the user belongs to is quite a common activity. Hopefully, this example will help and please let me know if you find other ways of using this and saving yourselves some time.

 

What data are you constantly having to evaluate that could be stored in the session?

17 Comments