Add Advanced Reference Qualifier to Variable Set that is dependent on a Catalog Item field

Bianca1
Giga Contributor

I am trying to add a Reference Qualifier on a Variable Set that is viewed when ordering a Catalog Item(below) named 'Random Test'. The Variable Set holds the Variable Products which is a reference field. Shown below:

find_real_file.pngI want the list of products(above) from that field to be dependent on a list field Product(s) on the Catalog Item. Shown Below:

find_real_file.png

My plan was to create a Script Include that gets an array of Product(s) from the Catalog Item and add that to the reference qualifier field to the Product Field when ordering 'Random Test'.

Here is a snippet of my code from my Script Include(RequestManagerUtils) the function(getRMProducts) is supposed to get a list of the Product(s).
Product(s) field is 'u_product_s'

getRMProducts: function() {
	var productList = [];
		
	var gr = new GlideRecord("sc_cat_item");
	gr.addQuery("name", gs.getValue("name", gs.getValue("name")));
	gr.query();
		
	while (gr.next()) {
		productList.push(gr.getValue('u_product_s'));
	}
		
	return 'sys_idIN' + productList.join(',');
}

Here is the Reference qualifier on the Product variable:

javascript:RequestManagerUtils().getRMProducts();

 

I feel the biggest part where I am messing up is querying the sc_cat_item table to get the list of Product(s). I am not quite sure how to access the catalog item and the u_product_s field and how to return it in a way for the Product field to understand. 

1 ACCEPTED SOLUTION

vkachineni
Kilo Sage
Kilo Sage

getRMProducts: function(catalog_item_sys_id) {
var productList = ['-1']; //Start with a no match

var gr = new GlideRecord("sc_cat_item");
gr.addQuery("sys_id", catalog_item_sys_id);
gr.query();

while (gr.next()) {
productList.push(gr.getValue('u_product_s'));
}

return 'sys_idIN' + productList.join(',');
}


//Reference qualifier. please check if it is current.sys_id or current.something.sys_id to get the catalog item sys id

javascript:RequestManagerUtils().getRMProducts(current.sys_id);


background script test
var products = new RequestManagerUtils().getRMProducts('sys_id OF catalog item');
gs.info('products = ' + products);
//Expected sys_idINsys_id1,sys_id2

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

View solution in original post

5 REPLIES 5

Rahul Kumar17
Tera Guru
Hi, U can set advance reference qualifier Javascript :products=products.variables.name of variable
If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

vkachineni
Kilo Sage
Kilo Sage

getRMProducts: function(catalog_item_sys_id) {
var productList = ['-1']; //Start with a no match

var gr = new GlideRecord("sc_cat_item");
gr.addQuery("sys_id", catalog_item_sys_id);
gr.query();

while (gr.next()) {
productList.push(gr.getValue('u_product_s'));
}

return 'sys_idIN' + productList.join(',');
}


//Reference qualifier. please check if it is current.sys_id or current.something.sys_id to get the catalog item sys id

javascript:RequestManagerUtils().getRMProducts(current.sys_id);


background script test
var products = new RequestManagerUtils().getRMProducts('sys_id OF catalog item');
gs.info('products = ' + products);
//Expected sys_idINsys_id1,sys_id2

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Hi vkachineni,

 

Thank you. The sys_id query worked. I don't know why I didn't think about the the sys_id.. 


When I ran the background script, it worked as expected. The Reference Qualifier is not working though. I think it has to do with the 'current.sys_id', I will need to look into how to get that value.

Hey! This thread has been extremely helpful but im stuck here where you left off. Did you find a solution for getting 'current.sys_id' in the reference qual?