- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-23-2019 01:00 PM
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:
I want the list of products(above) from that field to be dependent on a list field Product(s) on the Catalog Item. Shown Below:
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-23-2019 01:49 PM
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
Vinod Kumar Kachineni
Community Rising Star 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-23-2019 01:38 PM
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-23-2019 01:49 PM
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
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-23-2019 02:52 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-15-2020 05:06 PM
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?