
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2015 07:47 AM
Hi all,
I am trying to check a user's group membership using a client script but I am not having any luck... below is a screen shot of what I have written but it is not working. Could some one please point me in the right direction to achieve this.
onChange client script
table: incident
field name: caller
script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//Checks to see if user is a member of the "App-SNIncident-StoreUser".
//If true, "is a Store" field is marked as true. Used for determing what CIs to show in the incident form.
var ourUser = g_form.getValue('caller_id');
//var group = 'ec00d5fd6fff11006bceaf512e3ee4a7';
//var caller = ourUser;
var storeUser = ourUser.isMemberOf('ec00d5fd6fff11006bceaf512e3ee4a7'); //Storeuser
if(storeUser){
g_form.setValue('u_is_a_store',true);
} else{
g_form.setValue('u_is_a_store', false);
}
}
I keep getting this error message saying 'isMemberOf' is not a function, but I am not sure what other function to use... I need to be able to check the caller's group membership if it changes to check and uncheck the 'is a store' field... any ideas? Please help!!
Thank you,
Yeny.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2015 07:59 AM
It looks like you are trying to utilize .isMemberOf which is a method only available to the Server-side gs object. I think you need to just run an it in a GlideRecord
var person = g_form.getValue('caller_id');
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', 'App-SNIncident-StoreUser');
ir.addQuery('user', person);
ir.query();
if(ir.next()){
g_form.setValue('u_is_a_store', true);
}else{
g_form.setValue('u_is_a_store', false);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2015 07:57 AM
Hi Yeny,
You have to run this at server side.You can do the glideajax and pass the parameters to get the output.
http://wiki.servicenow.com/index.php?title=GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2015 07:59 AM
It looks like you are trying to utilize .isMemberOf which is a method only available to the Server-side gs object. I think you need to just run an it in a GlideRecord
var person = g_form.getValue('caller_id');
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', 'App-SNIncident-StoreUser');
ir.addQuery('user', person);
ir.query();
if(ir.next()){
g_form.setValue('u_is_a_store', true);
}else{
g_form.setValue('u_is_a_store', false);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2015 10:07 AM
Thank you so much Kenneth, this worked for me to achieve what I needed to do. It wasn't working at first but I changed the group to be the sys_id instead of the display name, shown below:
script:
var person = g_form.getValue('caller_id');
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', 'ec00d5fd6fff11006bceaf512e3ee4a7');
ir.addQuery('user', person);
ir.query();
if(ir.next()){
g_form.setValue('u_is_a_store', true);
}
else{
g_form.setValue('u_is_a_store', false);
}
}
Do you think I can query the CMDB based on this script to only show specific CIs when the 'is a store' button is selected. If so, how can I do that? Should I do a GlideRecord in the client script... I've tried using a script include but I can't use a dictionary override for the same table (incident) on the cmdb_ci field... Do you have any thoughts on that?
Please let me know, thank you so much for your help!
Yeny

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2015 10:11 AM
Hi Yeny,
You can use the reference qualifier to restrict the data as per the condition.Here is the more info on it.
http://wiki.servicenow.com/index.php?title=Reference_Qualifiers