Filter CIs on record producer form

Joshuu
Kilo Sage

Hi All,

 

In our instance, on the incident form the configuration is filtered based on category and subcategory.

priyarao_0-1709216383289.png

 

Below is the screenshot of dictionary override entry of configuration item field for incident table. Here, it is checking the script include "cat_subcatCI_INC()".

priyarao_1-1709216383295.png

 

Script include: In this script it is checking a custom table "CI Categorizations" where will have category, subcategory and CI tables. Please find the below reference screenshot.

function cat_subcatCI_INC(){
var configitems = [];   // array of group sys_ids to return to the calling reference qualifier
	
	if (!current.category.nil()) {
		var category = current.category;   
		var subcat=current.subcategory;// from the task form
		var gr = new GlideRecord('u_ci_categories_subcategoreis'); //Where CI to group relationship is store.
		gr.addQuery('u_category', category);
		gr.addQuery('u_subcategory',subcat);
		gr.query();
		if (gr.hasNext()) {
			while (gr.next()) {
				gs.log('Table Nameeeee is:'+gr.u_ci_table);
				var id=gr.u_ci_table;
				var arr=id.split(',');
				for(i=0;i<arr.length;i++){
				var gt=new GlideRecord('sys_db_object');
				gt.get(arr[i]);		
					configitems.push(gt.name);
				}
			}
			gs.log('configItems are:'+configitems);
			return 'sys_class_nameIN' + configitems.join(',')+'^operational_status!='+2+'^operational_status!='+10;	
		}
	}
	}

priyarao_2-1709216383303.png

 

priyarao_3-1709216383305.png

 

So, now the requirement is to implement same for a record producer. I have created the 3 variables category, subcategory and configuration item on the record producer form where user raise a request when there is an issue. But how to implement this logic, how to call this script include client side or do we need to create a new script include? 

 

Can we do it through a script include and a client script? Please assist.

 

Thanks & Regards.

8 REPLIES 8

Anubhav24
Mega Sage

Hi @Joshuu ,

 

On your Record Producer , you can achieve this through onChange Client Script written on field <subcategory> provided the category is selected from your client script you can pass two values[cat and subcat] to your script include and return the list of sys_ids of the CIs and then populate the field on your record producer . Or you can create a reference qualifier on your CI field on record producer and then call your script include directly by passing the two values of cat and subcat but in your case the SI on INC is without parameters so I think you may need to duplicate the SI and add two parameters to the function call.

 

Please mark correct/helpful if my response helped you.

Hi @Anubhav24 ,

 

Could you please help me with on change client script and script include.

 

Please assist. 

 

Thanks & Regards.

Hi @Joshuu ,

You can refer to below developer article to create your own Client Script and Script Include.

https://www.servicenow.com/community/developer-articles/how-to-call-script-include-from-client-scrip...

 

Please mark helpful/correct if my response helped you.

Hi @Anubhav24 ,

 

I know this article. But I am stuck at client script. I am not getting how to filter cis. Do we need to use setvalue?

 

Because here I want to show cis based on the subcategory. It is not just a value to set. 

 

Please help.