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.

List Collector dynamic reference qual

Kiran Patil3
Giga Expert

Hi,

I am trying to filter list collector based on other variable selected in catalog item. I have two variables company and Manufacturer.

I am trying to display list of CI based on Company and also based on Manufacturer if selected.

 

// eed4f8e687afa100cb0ab92489434d3e  Manufacturer
gs.print(getCusotmerApplications('cd91b60b1bc9c010e8e30dc8cd4bcb63',''));

function getCusotmerApplications(company,manufacturer1)
	{
		var SysIds = [];
		var applications = new GlideRecord('cmdb_ci_linux_server');
		gs.addInfoMessage(manufacturer1);
		applications.addEncodedQuery('company='+company);
		if(manufacturer1!= null || manufacturer1!= '' || manufacturer1 != undefined || manufacturer!= 'undefined'){ gs.addInfoMessage("Inside if"+ manufacturer1); applications.addQuery('manufacturer', manufacturer1);	}
		applications.query();
		while(applications.next())
			{

				SysIds.push(applications.sys_id.getValue());
			}
		return 'sys_idIN'+SysIds;
	}

If I dont pass the manufacturer, I am getting Null result.

I should ALL CI of company and If Manufacturer is selected, add additional criteria.

Any idea !!

1 REPLY 1

Michael Jones -
Giga Sage

You can create a dynamic filter that is dependent on the values of other catalog items fields using a variable attribute. Assuming you have a field on the Catalog Item with a name of "company" and another one named "manufacturer1", you would add a variable attribute to your list collector (same tab as default value) of: 

ref_qual_elements=company;manufacturer1

And then add a Reference qualifier of:

javascript: if(current.variables.manufacturer1) { 'company=' + current.variables.company + '^manufacturer=' + current.variables.manufacturer1} else {'company=' + current.variables.company };

Now, on the form, when you select just a company you will get all values in the list collector that match the company selected. If you then select a manufacturer1 value, the filter will be further refined. This assume you are using the out of the box fields Company and Manufacturer on the cmdb_ci_linux_server table. 

This attribute tells the system to watch for changes to the field names you list, and when detected, send back server-side to re-evaluate the results of the reference qualifier. The reference qualifier used javascript to determine if you are passing a value for manufacturer1 and, based on the results, set the qualifier string appropriately. 

If this was helpful, or correct, please be kind and remember to click appropriately!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!