- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2022 05:26 AM
Hi All,
I need to populate assignment group with the group to which Subject person belongs. I need to validate for below groups if Subject person is member or not-
1) Supplier Onboarding - CCS
2) Supplier Onboarding - Client Services
3) Supplier Onboarding - Implementations
I have written below SI-
var SupplierOnboardingCustomUtils1 = Class.create();
SupplierOnboardingCustomUtils1.prototype = {
initialize: function() {},
populateGroups: function(subjectPerson) {
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', subjectPerson);
gr.addQuery('group', '515e3a461b644110050ddc68b04bcbea').addOrCondition('group', 'cd1d36061b644110050ddc68b04bcbf4').addOrCondition('group', '77fd76061b644110050ddc68b04bcb00'); //Supplier Onboarding - CCS OR Supplier Onboarding - Client Services OR Supplier Onboarding - Implementations
gr.query();
if (gr.next()) {
return gr.group.toString();
//return "sys_id="+gr.group.toString();
}
},
type: 'SupplierOnboardingCustomUtils1'
};
it is giving correct result but as per feedback I need to use system property to store group sys id. and need run a for loop to add orCondition. So I have created system properties named- sn_hr_le.supplier.onboarding.groups
This is the BR which is calling SI-
current.assignment_group = new SupplierOnboardingCustomUtils1().populateGroups(current.subject_person);
current.assigned_to = current.opened_by;
current.update();
Any one can please help me to modify script to call system property and running for loop?
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2022 07:01 AM
Hi,
update script as this
var SupplierOnboardingCustomUtils1 = Class.create();
SupplierOnboardingCustomUtils1.prototype = {
initialize: function() {},
populateGroups: function(subjectPerson) {
var groups = gs.getProperty('sn_hr_le.supplier.onboarding.groups'); // get comma separated list of group sys_id's
var queryString = 'group.sys_idIN' + groups;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', subjectPerson);
gr.addEncodedQuery(queryString);
gr.setLimit(1);
gr.query();
if (gr.next()) {
gs.info("User is Member of Group!");
gs.info('returned group is:' + gr.group.toString());
return gr.group.toString();
}
else {
gs.info("User is Not a Member of Group!");
return '';
}
},
type: 'SupplierOnboardingCustomUtils1'
};
Script
var group = new SupplierOnboardingCustomUtils1().populateGroups(current.subject_person);
if(group){
current.assignment_group = group;
}
current.assigned_to = current.opened_by;
current.update();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2022 05:47 AM
Hi Rekha,
I think you can use a different operator rather than using a for loop.
You can use something like:
var groupString = gs.getProperty('sn_hr_le.supplier.onboarding.groups');
var queryString = 'group.sys_idIN' + groupString;
gr.addEncodedQuery('group', queryString);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2022 06:00 AM
Hi,
You can use the way suggested by
var groups = gs.getProperty('sn_hr_le.supplier.onboarding.groups');// get comma separated list of group sys_id's
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', subjectPerson);
gr.addEncodedQuery('groupIN'+groups.toString());
if (gr.next()) {
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2022 06:47 AM
Hi
This is not working-
var SupplierOnboardingCustomUtils1 = Class.create();
SupplierOnboardingCustomUtils1.prototype = {
initialize: function() {},
populateGroups: function(subjectPerson) {
// var gr = new GlideRecord('sys_user_grmember');
// gr.addQuery('user', subjectPerson);
// gr.addQuery('group', '515e3a461b644110050ddc68b04bcbea').addOrCondition('group', 'cd1d36061b644110050ddc68b04bcbf4').addOrCondition('group', '77fd76061b644110050ddc68b04bcb00'); //Supplier Onboarding - CCS OR Supplier Onboarding - Client Services OR Supplier Onboarding - Implementations
// gr.query();
// if (gr.next()) {
var groups = gs.getProperty('sn_hr_le.supplier.onboarding.groups'); // get comma separated list of group sys_id's
var queryString = 'group.sys_idIN' + groupString;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', subjectPerson);
//gr.addEncodedQuery('groupIN' + groups.toString());
gr.addEncodedQuery('group', queryString);
if (gr.next()) {
gs.info("User is Member of Group!");
gs.info('returned group is:' + gr.group.toString());
return gr.group.toString();
}
//return "sys_id="+gr.group.toString();
else {
gs.info("User is Not a Member of Group!");
}
},
type: 'SupplierOnboardingCustomUtils1'
};
FYI- Subject person can be either one of the mentioned group so we are considering OR. will this encoded query will work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2022 07:04 AM
You've mixed up Anil and Mike's code, you've got the groups variable from Anil but the encodedQuery line from Mike. Just use the code Anil provided and you'll be good to go.