- 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 03:14 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+ "Option is : "+option_sys_id;
sd = sd+" "+qGr.question_text+" : "+cGr.sys_id.toString();
}
//task.short_description = 'Option is - ' + option_sys_id + 'Region: ' + current.variables.region.sys_id.toString(); + 'Machine Type: ' + current.variables.machine_type.sys_id.toString();
task.short_description = sd;
I have changed some logic as per my understanding but you can use EncodedQuery part and update loops as per your requirement.
Or let us know what is expected output in Short Description.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 04:06 AM - edited 12-01-2023 04:07 AM
@Anil Lande sir this is not working. could you please try this in your instance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 04:41 AM
What is expected output in Short Description field?
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 04:55 AM - edited 12-01-2023 04:55 AM
@Anil Lande Sir, Sorry that was working but the output is having some glitch, I believe you can rectify the same. below is the final script-
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+ "Option is : "+option_sys_id;
sd = sd+" "+qGr.question_text+" : "+cGr.sys_id.toString();
}
task.description = sd;
O/P :
As you can see sys_id is correctly displayed but each got repeated twice as below set:
Option is: <sys_id of option selected in variable Choose one of the following>
Choose one of the following : <sys_id of option selected in variable Choose one of the following>
Option is: <sys_id of option selected in variable Machine Type>
Type of Machine : <sys_id of option selected in variable Machine Type>
Option is: <sys_id of option selected in variable Region>
Region: <sys_id of option selected in variable Region>
Could you please help here so that it will display sys_id only one time not in sets.
Thanks