- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2022 03:01 PM
Hi There,
I am working on how to get the variables from a specific catalog item from the request item table (sc_req_item) and I have created a small portion of code but it is not working, I am not sure if this is the right way but I appreciate any help on this.
This portion of the code gets the specific catalog item from the "sc_req_item" table then I get the requests item number and validate these numbers on the "sc_item_option_mtom" table in order to get the question and value from each request item but when I run the hard code it is no retrieving any value from the table "sc_item_option_mtom" and I don't know why.
I believe may be is becasue of the gr2.addQuery("request_item.number", ritm.number); but i am not sure.
Example;
var catItem = '' "; // Catalog Item sys_id
var ritm;
var gr = new GlideRecord('sc_req_item');
gr.addQuery("cat_item", catItem );
gr.query();
while(gr.next()){
ritm = gr;
// gs.print("Number " + ritm.number);
for(var i = 0; i < ritm.length; i++){
var gr2 = new GlideRecord('sc_item_option_mtom');
gr2.addQuery("request_item.number", ritm.number);
gr2.query();
while(gr2.next()){
var ritmVariables = gr2;
// gs.print("Parent Item " + ritmVariables.request_item + " - Question " + ritmVariables.sc_item_option.item_option_new + " - Value " + ritmVariables.sc_item_option.value);
}
}
}
Thank you
Juan
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 07:26 AM
Can you try this pls,
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('cat_item', '8514b37e2f6a8110379a5e072799b6dc');
ritmGr.query();
//For Testing comment WHILE loop and uncomment IF loop
while(ritmGr.next()) {
//if(ritmGr.next()) {
gs.print(ritmGr.number + ': ' + getVariableResponse(ritmGr));
}
function getVariableResponse(ritmGr) {
var list = [];
var scOptionGr = new GlideRecord('sc_item_option_mtom');
scOptionGr.addEncodedQuery('request_item=' + ritmGr.sys_id);
scOptionGr.query();
while(scOptionGr.next()) {
list.push('Question: ' + scOptionGr.sc_item_option.item_option_new.getDisplayValue() + '\tQuestion Sys ID: ' + scOptionGr.sc_item_option.item_option_new + '\tValue: ' + scOptionGr.sc_item_option.value);
}
return list;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2022 04:33 PM
Hi Juan,
The format is as below in server-side script. To get the sys_id of requested_for variable on the form, open up the variable definition page for the variable requested_for and right click on the header and select sys_id.
r.addQuery(variables.' + <variable sys_id> + '=' + <variable value to query>);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2022 10:48 PM
FYI,
I've provided code to fetch the variable from server script in the following thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2022 10:16 PM
Hi
Please check the code provided below:
getRitmByCitem('<your_citem_sys_id_goes_here>');
function getRitmByCitem(citemID) {
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('cat_item', citemID);
ritmGr.query();
//For Testing comment WHILE loop and uncomment IF loop
while(ritmGr.next()) {
//if(ritmGr.next()) {
gs.print(getVariableResponse(ritmGr));
}
}
function getVariableResponse(ritmGr) {
var scOptionGr = new GlideRecord('sc_item_option_mtom');
scOptionGr.addEncodedQuery('request_item=' + ritmGr.getValue('sys_id'));
scOptionGr.query();
while(scOptionGr.next()) {
return 'Parent Item: ' + ritmGr.number + '\tQuestion: ' + scOptionGr.sc_item_option.item_option_new.getDisplayValue() + '\tQuestion Sys ID: ' + scOptionGr.sc_item_option.item_option_new + '\tValue: ' + scOptionGr.sc_item_option.value;
}
}
Please check and let me know if this helps!
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 07:11 AM
Hi Kartik,
Thank you for your help, I test with a while loop and it does return one variable from each request item where it should return all variables to each request item that belong to the specific catalog item.
Regards,
Juan