Need assistance on creating a Reference Qualifier on a variable in a Catalog Item

JoSte
Tera Contributor

Dear,

 

I'm busy with creating a new Catalog Item.  I first create a variable called 'Service_Catalog' where I'm asking the enduser to select one of the existing Service Catalogs (sc_catalog.list). Now I like that the end user selects in a second variable called 'Catalog' only one category of the existing categories of the Service Catalog selected in the previous variable (Service_Catalog).  I know I need to use a Reference Qualifier but I have no knowledge about Java scripting. Can someone help me in telling me how I can show in the variable 'Categorie' only the Categories that belongs to the Service Catalog entere in the variable 'Service Catalog'.

 

Many thanks for helping me out.

 

-Jo-

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage
Giga Sage

Hi @JoSte ,

 

you can create a script include and call that script include through reference qualifier as shown below,

 

on the field 'Catalog' go to advanced reference qualifier and add below code 

 

javascript: new getServiceCatalog().getCategories(current.variables.service_catalog);

 

 

In script include try :

 

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

    getCategories: function(serviceCategories) {
		var arr = [];
        var gr = new GlideRecord('sc_category');
        gr.addQuery('sc_catalog', serviceCategories);
		gr.query();
		while(gr.next())
		{
			arr.push(gr.sys_id.toString());
			
		}
		return 'sys_idIN'+ arr.toString();

    },

    type: 'getServiceCatalog'
});

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

1 REPLY 1

swathisarang98
Giga Sage
Giga Sage

Hi @JoSte ,

 

you can create a script include and call that script include through reference qualifier as shown below,

 

on the field 'Catalog' go to advanced reference qualifier and add below code 

 

javascript: new getServiceCatalog().getCategories(current.variables.service_catalog);

 

 

In script include try :

 

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

    getCategories: function(serviceCategories) {
		var arr = [];
        var gr = new GlideRecord('sc_category');
        gr.addQuery('sc_catalog', serviceCategories);
		gr.query();
		while(gr.next())
		{
			arr.push(gr.sys_id.toString());
			
		}
		return 'sys_idIN'+ arr.toString();

    },

    type: 'getServiceCatalog'
});

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang