To display sys_id of selected 3 variable's value in Short Desc. of task through wf catalog task

rishabh31
Mega Sage

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

 

 

1 ACCEPTED SOLUTION

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. 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

9 REPLIES 9

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;
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

@Anil Lande Sir, No sir I think you got me wrong.

Now the O/p is

rishabh31_0-1701436268818.png

My Expected O/P is shown below:

rishabh31_1-1701436383290.png

 

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. 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Ankur Bawiskar
Tera Patron
Tera Patron

@rishabh31 

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?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@rishabh31 

Any response to my above comment?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader