g_user for company name, or users group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2012 10:18 AM
In a client script I would like to use g_user to get the users company and groups instead of a call to the server, as recommended. the wiki tells me I could use the session.established event to create the variable I want to use in the client script as g_user.userCompanyName, or, more challenging, an array of g_user.userGroupFullNames.
in the script for gs.getSession().putClientData('userCompanyName', 'value1');
how do I get value1 to be the users company name ? with std glide ?
I have this script for event session.established:
var u_id=gs.getUserID();
//gs.log(u_id);
var value1='defaultValue';
var usr=new GlideRecord('sys_user');
usr.addQuery('sys_id',u_id);
usr.query();
while (usr.next()) {
value1=usr.company.name
}
gs.getSession().putClientData('CompanyName', 'value1');
my client script has this:
var UserCoName = g_user.getClientData('CompanyName');
alert('CompanyName returned as:'+UserCoName);
but UserCoName is undefined.
I made sure to not log in my test client session until after I saved the script action
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2012 11:28 AM
My guess is that the Script Action you created does not have Synchronous enabled, and therefore cannot be triggered and returns undefined.
According to the Wiki (http://wiki.service-now.com/index.php?title=Session_Client_Data), they indicate that Synchronous should be checked. Make sure that the Synchronous is visible on the form and that it is enabled.
I hope this is helpful,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2012 11:51 AM
Thank you - but I have no such field to chose - I guess I'd have to create it - but I see in the sncguru site, when I looked up synchronous, that I could try "g_form getReference Callback" instead, which says it would be better that a "normal" server call because it is asynchronous (and maybe almost as good as a field captured from Session_Client_data).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2015 11:24 PM
Old post, but still a follow up. The synchronous field is not visible due to an ACL on that table. It is intended that this field is only be set by ServiceNow support. Either raise a ticket in HI oder disable the respective ACLs to set synchronous.