- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 02:34 AM
Team,
I have 3 variables 'Choose one of the following', 'Region' and 'Machine Type' all are select box type variables and each variable has 4 choices/options. I want to display this option's sys_id In the short description of sc_task for which I am using a Catalog task activity containing the below advanced script. For 1st variable 'Choose one of the following' it is working fine as there was GlideRecord but for the rest 2 variables ('Region' and 'Machine Type') choices I am unable to display their sys_ids through the below script-
var option_sys_id = "";
var qGr = new GlideRecord("item_option_new");
qGr.addQuery("cat_item", current.cat_item);
qGr.addQuery("name", "choose_one_of_the_following");
qGr.query();
if (qGr._next()) {
var cGr = new GlideRecord("question_choice");
cGr.addQuery("question", qGr.getUniqueValue());
cGr.addQuery("value", current.variables.choose_one_of_the_following);
cGr.query();
if (cGr._next()) {
option_sys_id = cGr.sys_id + '';
}
}
task.short_description = 'Option is - ' + option_sys_id + 'Region: ' + current.variables.region.sys_id.toString(); + 'Machine Type: ' + current.variables.machine_type.sys_id.toString();
I even used the below syntaxes to display sys_id of the option selected in Variables 'Region' and 'Machine Type' but no luck
current.variables.<variable_name>.sys_id.getValue();
OR
current.variables.<variable_name>.getUniqueValue();
I can GlideRecord for each of the Variables as did for 1st Variable but it will make the advanced script looks long and not good.
Because I am unable to get other 2 variable's value's sys_id to call on the above single Gliderecord that is the reason requesting help to modify the above single GlideRecord script in such a way that all 3 variables selected option's sys_id should display accordingly in task short_description.
Kindly help.
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 05:48 AM
Hi,
Please try below:
var option_sys_id = "";
var sd = "";
var qGr = new GlideRecord("item_option_new");
qGr.addQuery("cat_item", current.cat_item);
qGr.addEncodedQuery("nameINchoose_one_of_the_following,region,machine_type"); // to query more variables
qGr.query();
while (qGr._next()) {
var cGr = new GlideRecord("question_choice");
cGr.addQuery("question", qGr.getUniqueValue());
cGr.addQuery("value", current.variables[qGr.name.toString()]);
cGr.query();
if (cGr._next()) {
option_sys_id = cGr.sys_id + '';
}
sd = sd+ "\nOption is : "+option_sys_id;
sd = sd+" \n"+qGr.question_text+" : "+qGr.sys_id.toString()+"\n";
}
task.description = sd;
Now you should have different sys_id's.
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 05:05 AM
Hi,
Please try below:
var option_sys_id = "";
var sd = "";
var qGr = new GlideRecord("item_option_new");
qGr.addQuery("cat_item", current.cat_item);
qGr.addEncodedQuery("nameINchoose_one_of_the_following,region,machine_type"); // to query more variables
qGr.query();
while (qGr._next()) {
var cGr = new GlideRecord("question_choice");
cGr.addQuery("question", qGr.getUniqueValue());
cGr.addQuery("value", current.variables[qGr.name.toString()]);
cGr.query();
if (cGr._next()) {
option_sys_id = cGr.sys_id + '';
}
sd = sd+ "\nOption is : "+option_sys_id;
sd = sd+" \n"+qGr.question_text+" : "+cGr.sys_id.toString()+"\n";
}
task.description = sd;
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 05:13 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 05:48 AM
Hi,
Please try below:
var option_sys_id = "";
var sd = "";
var qGr = new GlideRecord("item_option_new");
qGr.addQuery("cat_item", current.cat_item);
qGr.addEncodedQuery("nameINchoose_one_of_the_following,region,machine_type"); // to query more variables
qGr.query();
while (qGr._next()) {
var cGr = new GlideRecord("question_choice");
cGr.addQuery("question", qGr.getUniqueValue());
cGr.addQuery("value", current.variables[qGr.name.toString()]);
cGr.query();
if (cGr._next()) {
option_sys_id = cGr.sys_id + '';
}
sd = sd+ "\nOption is : "+option_sys_id;
sd = sd+" \n"+qGr.question_text+" : "+qGr.sys_id.toString()+"\n";
}
task.description = sd;
Now you should have different sys_id's.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 03:16 AM
what's the business value of showing sysId to the agent who will work on that catalog task?
Wouldn't it make more sense showing the label instead of the sysId?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 05:37 AM
Any response to my above comment?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader