Filter Reference Field based on Assignment Group

Curtis Lewis
Tera Expert

Good morning,

 

I added a reference field to our incident form, that references the TAGs table (label), it's configured as a drop down with --None-- option so users can "Tag" the expected cause of an incident while closing the case.

I want to show specific Tags (that I have created in the Tags table as global tags), depending on what assignment group the incident is assigned too (assignment_group).

For the life of me I can't figure out how to make this work given there are multiple assignment groups and only a subset of Tags I want to show for each, while some tags will be visible for more than one assignment group.

CurtisLewis_0-1671485003832.png

Options:
SNAG - IT User Services Team
SNAG - IT Infrastructure Team
SNAG - IT Integrations Team

Tag Visible to User ServicesVisible to InfrastructureVisible to Integrations
Data Defectnny
User Trainingyyy
Network Issueyyy
Hardware Issueynn



1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Since this relationship is not defined in a table anywhere, you'll have to manually build the list in a Script Include and return only the desired records.  So your Reference qualifier on your tag field would look something like this:

javascript: new IncidentUtils().getTags(current.assignment_group)

where : is actually the colon character, IncidentUtils is the name of a Client callable Script Include, and getTags is the name of a function in that SI.

If you want the reference field to appear as a drop-down list you'll also need to add this to the Attributes field in the Advanced Dictionary Entry view:

ref_auto_completer=AJAXReferenceChoice,ref_qual_elements=assignment_group

The Script Include would look like this:

var IncidentUtils = Class.create();
IncidentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getTags: function(ag) {
		var arr = [];
		var tags = new GlideRecord('label');
		tags.query();
		while (tags.next()) {
			if (ag == '019ad92ec7230010393d265c95c260dd') { //sys_id of AG1
				if (tags.name == 'User Training' || tags.name == 'Network Issue' || tags.name == 'Hardware Issue') {
					arr.push(tags.sys_id.toString());
				}
			}
			if (ag == '72910dd8779050108a370870a81061a9') { //sys_id of AG2
				if (tags.name == 'User Training' || tags.name == 'Network Issue') {
					arr.push(tags.sys_id.toString());
				}
			}
			if (ag == '0a52d3dcd7011200f2d224837e6103f2') { //sys_id of AG3
				if (tags.name == 'Data Defect' || tags.name == 'User Training' || tags.name == 'Network Issue') {
					arr.push(tags.sys_id.toString());
				}
			}
		}
		
		return 'sys_idIN' + arr.join(',');
	},
    type: 'IncidentUtils'
});

 

 

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Since this relationship is not defined in a table anywhere, you'll have to manually build the list in a Script Include and return only the desired records.  So your Reference qualifier on your tag field would look something like this:

javascript: new IncidentUtils().getTags(current.assignment_group)

where : is actually the colon character, IncidentUtils is the name of a Client callable Script Include, and getTags is the name of a function in that SI.

If you want the reference field to appear as a drop-down list you'll also need to add this to the Attributes field in the Advanced Dictionary Entry view:

ref_auto_completer=AJAXReferenceChoice,ref_qual_elements=assignment_group

The Script Include would look like this:

var IncidentUtils = Class.create();
IncidentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getTags: function(ag) {
		var arr = [];
		var tags = new GlideRecord('label');
		tags.query();
		while (tags.next()) {
			if (ag == '019ad92ec7230010393d265c95c260dd') { //sys_id of AG1
				if (tags.name == 'User Training' || tags.name == 'Network Issue' || tags.name == 'Hardware Issue') {
					arr.push(tags.sys_id.toString());
				}
			}
			if (ag == '72910dd8779050108a370870a81061a9') { //sys_id of AG2
				if (tags.name == 'User Training' || tags.name == 'Network Issue') {
					arr.push(tags.sys_id.toString());
				}
			}
			if (ag == '0a52d3dcd7011200f2d224837e6103f2') { //sys_id of AG3
				if (tags.name == 'Data Defect' || tags.name == 'User Training' || tags.name == 'Network Issue') {
					arr.push(tags.sys_id.toString());
				}
			}
		}
		
		return 'sys_idIN' + arr.join(',');
	},
    type: 'IncidentUtils'
});

 

 

In ServiceNow incident form we have reference field business services('cmdb_ci_service'), whenver i selected assignment group 'SAP', it should filter only SAP services in the business services field