
- 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 10:49 AM
Hi Pradeep,
I tried adding a script include to the attributes field in the 'incident' table dictionary override for the 'cmdb_ci' field... I don't think I am doing this correctly... Am I writing the script include correctly?
Script include:
function CheckIsMemberOfStore() {
var a = current.u_is_a_store;
//var b = current.cmdb_ci.sys_class_name;
// return a query string
if(a == false){
return;
}
else if(a == true){
// return applications that are marked as 'store applications' and hardware items that have a class of 'store hardware'
return 'sys_class_name=u_cmdb_ci_store_hardware^ORref_cmdb_ci_appl.u_store_application=true';
//^ORsys_class_name=cmdb_ci_application_software.u_store_application=true
}
}
This is where I added the script include... not sure if this is the best way to do it...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2015 05:59 AM
Thank you Kenneth for helping me with this script!
Yeny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2016 04:08 AM
I tried this, but not all users have access to the sys_user_grmember table, so some would return false for "hasNext()", despite them being in a group. How should i fix that?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2016 12:33 PM
Thank you, I was struggling with this and an ACL was the answer for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2016 01:18 PM
GlideAjax makes it possible to have the client script call the server to retrieve that information in an efficient and effective manner. You can return simple or complex data types and then use that information on the client script. http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#gsc.tab=0