Show variables of Selected Catalog Item on Portal while raising a new request for Modification.

Naveen87
Tera Guru

Hi Developers,

 

I'm trying to build a new Catalog Item for Minor changes required on existing Catalog Item on the system.

I just have rough design in my mind & I was wondering,

How can I create a variable in New Item, Which will show all variable of the selected Catalog Item that user wants to modify.

 

Ex:- Below I have selected "Naveen Learning" Catalog Item.

Now I want to create a new variable below this ("Select Catalog Item") which will show all available variable under this Item. So user can select for modification.

 

Naveen87_1-1677248105840.png

I tried to create a variable referencing to item_option_new table but this show all the variables available in the system. I need to show only which are related to above selected Catalog Item.

 

 

 

Please suggest.

 

Thank you.

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Naveen87 

variables can be directly linked to catalog item or they can be part of some variable set

so use this; you need to use script include for this

javascript:'cat_item='+ current.variables.choose_variable_from_the_catalog + '^ORsys_idIN' + fetchVariables(current.variables.choose_variable_from_the_catalog);
function fetchVariables(itemSysId){

	var arr = [];
	var gr = new GlideRecord("io_set_item");
	gr.addQuery("sc_cat_item", itemSysId);
	gr.query();
	while(gr.next()) {
		var rec = new GlideRecord('item_option_new');
		rec.addQuery('variable_set', gr.variable_set);
		rec.query();
		while(rec.next()){
			arr.push(rec.getUniqueValue());
		}
	}
	return arr.toString();

}

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

View solution in original post

10 REPLIES 10

Allen Andreas
Administrator
Administrator

Hi,

You'd want to do something like what you've already done, but then add filtering to that variable reference field (go into the variable configuration/settings) to use the catalog item they selected in the previous field (select catalog item). So for filtering you can use:

 

 

javascript(colon)"cat_item="+current.variables.select_catalog_item_field_name_here;

 

It's javascript and then a : next to it, but the forums strip it out when I post so I had to post it like I did above.

 

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

 

Thank you for the response.

I have tried this but no luck. 

Not sure if I have done it in right way.

Please look & suggest

 

I can't use static Item here so used the variable Name which hold current Item value.

Naveen87_3-1677254993750.png

 

Naveen87_0-1677254936030.png

 

Naveen87_1-1677254960558.png

 

Naveen87_2-1677254969999.png

 

Hi,

As I mentioned in my reply....please refer to the bold statement:

It's javascript and then a : next to it, but the forums strip it out when I post so I had to post it like I did above.

 

It's not javascript(colon)...


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Pooja Mallikarj
Kilo Sage

Hi, @Naveen87  change "Use Reference Qualifier" type as Advanced and update the script line as below.

 

PoojaMallikarj_0-1677262657055.png

Thanks,

Pooja M