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

Allen Andreas
Administrator
Administrator

You'd need to pass your current object in the script include I believe. I think only in conditions does current record come along.

In your reference qualifier, when you're calling the script include and function add (current) in the function call. And then in script include, add current in the function call as well so that you're bringing it the function parameter in.

Assuming the rest of your code is correct and it's actually finding a group, etc.

Otherwise, yeah, you don't need all that, you can follow Mike's guidance below, but...all users will show until the assignment group is filled in. So my personal recommendation is to hide the assigned to variable via UI Policy, until an assignment group is chosen.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

I did that as per Mr Ankur Bawiskar's reply but still I see all users in the assigned to field.
Could there be something very obvious that I am missing here?

Hi,

I'm glad you got the correct answer. I don't believe the scope was mentioned as a fix to your issue, so I believe you actually figured out your own issue and resolved it?

If you did add the current object assignment group to your reference qualifier and passed that as a function parameter, that is what I mentioned above.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Mike Patel
Tera Sage

You don't all this just add below to assign to variable

javascript:'group='+current.variables.assignment_group;