Reference Qualifier to populate a field with two different fields on Change form

Lavanya Nagendr
Giga Guru

Hi All,

 

We have a requirement where we need to populate a reference field with values from two different reference fields on the form.

 

Say a reference field "Implementation Group" which currently have dependent field as "Assignment group" on the form. So when a user pick the field it will show the group members from the group on the Assignment group field. \

But now we need to make the "Implementation Group" field to show the members from both "Assignment group" field and an another "Owner group" field. so that when a user picks Implementation field it will show both the assignment group and the owner group members.

 

Note: I tried adding the "Owner group" in the Dependent field of that implementation group field but couldn't achieve the result. Can we achieve it through reference qualifier? If so kindly provide your solution for this.

1 ACCEPTED SOLUTION

Rahul Talreja
Mega Sage
Mega Sage

Hi @Lavanya Nagendr ,
Use script include as

 

//Script Include

var GroupMembers = Class.create();

GroupMembers.prototype = {

initialize: function() {
},

getGroupMembers: function(group1, group2) {
	var grp1 = new GlideRecord('sys_user_grmember');
	grp1.addQuery('group', group1);
	grp1.query();
	
	var grp2 = new GlideRecord('sys_user_grmember');
	grp2.addQuery('group', group2);
	grp2.query();
	
	var grpMembers = [];
	while (grp1.next()) {
		grpMembers.push(grp1.user.sys_id);
	}
	
	while (grp2.next()) {
		grpMembers.push(grp2.user.sys_id);
	}
	
	return 'sys_idIN'+ grpMembers.toString();
},

type: 'GroupMembers'

};

 


and call this from advance reference 

 

javascript : new GroupMembers().getGroupMembers(current.variables.group1, currenet.variables.group2;

 

Note: Please adjust the variable names of group1 and group2 as per your environment

 

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Lavanya Nagendr 

you cannot add 2 fields as dependent.

You need to use advanced ref qualifier and use script include; pass values for both the fields.

the script include function will then return the sysIds you want

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi Ankur,

 

This is my script include, Kindly help me on this whether this is right or not?

 

Ref Qualifier: javascript:"u_implementation_group="+new global.PR_PopulateImpValByField().getFields(current.assignment_group,current.u_owner_group);

 

Script Include:

var PR_PopulateImpValByField = Class.create();
PR_PopulateImpValByField.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFields:function(a,b){
var grp = [];
grp = a;
grp = b;
 
return grp;
},
 
 
    type: 'PR_PopulateImpValByField'
});
 
Note: all the 3 fields are refered to the "Group" table
 
 
Thanks,
Lavanya

@Lavanya Nagendr 

Looks good; just small update here since u_implementation_group is reference type

I believe you have added this advanced ref qualifier on u_implementation_group field

Ref Qualifier: javascript;"sys_idIN"+new global.PR_PopulateImpValByField().getFields(current.assignment_group,current.u_owner_group);

Implementation group field is reference to which table?

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

@Ankur Bawiskar 

 

Yes i have added this reference qualifier on "u_implementation_group" field and this field also referring to Group table.

 

the below reference qualifier didn't work. The reference field(u_implementation_group) shows no group members.

 

Ref Qualifier:    javascript:"sys_idIN"+new global.PR_PopulateImpValByField().getFields(current.assignment_group,current.u_owner_group);