Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Populate 'assigned to' field based on assignment group in catalog item.

Apex Predator
Kilo Expert

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:
find_real_file.png
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.

find_real_file.png

find_real_file.png
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'
};
1 ACCEPTED SOLUTION

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

sudha20
Tera Contributor

its working. thank you