- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2020 09:13 AM
Hello,
I am using Orlando version.
I created a catalog item with 'assigned to' and 'assignment group' as reference fields.
I only want to see the users in assigned to field who are part of the selected assignment group.
I created a Script Include 'ReferenceQualifierUtility' which returns a list of users based on the group selected. Attached a screenshot of it.
Script Include:
I created an advanced reference qualifier on 'assigned to' field. Screenshot attached. But still, the assigned to field shows all users even after selecting the assignment group.
Is there another way to do this? Or am I making a mistake?
Referenced this article but to no use:
https://community.servicenow.com/community?id=community_question&sys_id=65d147a9db98dbc01dcaf3231f96...
Thank you community.
Script which is easy to copy/modify:
var ReferenceQualifierUtility = Class.create();
ReferenceQualifierUtility.prototype = {
initialize: function() {
},
assignedDependency:function(){
gs.info("This is a test message");
var group = current.variables.assignment_group; // your assignment group variable name
var user_array = [];
if(group!=''){
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group',group);
getMembers.query();
while(getMembers.next())
{
user_array.push(getMembers.getValue('user'));
}
return 'sys_idIN' + user_array.toString();
}
else{
return 'active=true';
}
},
type: 'ReferenceQualifierUtility'
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2020 10:15 AM
Hi,
I assume your 1st variable refers to sys_user_group and name is assignment_group
2nd variable refers to sys_user table
it should work fine
Did you print the logs in script include
Also try using toString()
var ReferenceQualifierUtility = Class.create();
ReferenceQualifierUtility.prototype = {
initialize: function() {
},
assignedDependency:function(group){
gs.info('group is' + group);
var user_array = [];
if(group!=''){
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group',group.toString()); // updated this line
getMembers.query();
while(getMembers.next())
{
user_array.push(getMembers.getValue('user'));
}
gs.info('user array is' + user_array);
return 'sys_idIN' + user_array.toString();
}
else{
return 'active=true';
}
}
,
type: 'ReferenceQualifierUtility'
};
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
‎10-01-2020 09:29 AM
Hi,
you should update your reference qualifier as above
Pass the variable group value via current as below in advanced ref qualifier
javascript: new ReferenceQualifierUtility().assignedDependency(current.variables.assignment_group)
var ReferenceQualifierUtility = Class.create();
ReferenceQualifierUtility.prototype = {
initialize: function() {
},
assignedDependency:function(group){
var user_array = [];
if(group!=''){
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group',group);
getMembers.query();
while(getMembers.next())
{
user_array.push(getMembers.getValue('user'));
}
return 'sys_idIN' + user_array.toString();
}
else{
return 'active=true';
}
}
,
type: 'ReferenceQualifierUtility'
};
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
‎10-01-2020 09:43 AM
Changed it but still doesn't fix it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2020 10:15 AM
Hi,
I assume your 1st variable refers to sys_user_group and name is assignment_group
2nd variable refers to sys_user table
it should work fine
Did you print the logs in script include
Also try using toString()
var ReferenceQualifierUtility = Class.create();
ReferenceQualifierUtility.prototype = {
initialize: function() {
},
assignedDependency:function(group){
gs.info('group is' + group);
var user_array = [];
if(group!=''){
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('group',group.toString()); // updated this line
getMembers.query();
while(getMembers.next())
{
user_array.push(getMembers.getValue('user'));
}
gs.info('user array is' + user_array);
return 'sys_idIN' + user_array.toString();
}
else{
return 'active=true';
}
}
,
type: 'ReferenceQualifierUtility'
};
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
‎10-01-2020 10:28 AM
Thank you so much for spending the time. It worked after I changed the application scope to 'global'. My organization was somehow restricting access to SQA_dev application.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2020 10:54 AM
Glad to help.
Have a nice day
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader