To display sys_id of selected variable's value in Short Description of task through wf catalog task

rishabh31
Mega Sage

Team,

 

I have a variable 'Choose one of the following' select box type variable having 3 options, for 2nd option 'To avail upgraded version of MSOffice', 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 contains below advanced script 

 

current.state = 2; // Set RITM as WIP
task.assignment_group.setDisplayValue('Help Desk');
if ((current.variables.choose_one_of_the_following.getDisplayValue().indexOf('To avail upgraded version of MSOffice') > -1) && (current.variables.type_of_machine.getDisplayValue().indexOf('Physical') > -1)) {
    task.short_description = 'Asset tag ID - ' + current.variables.asset_tag.getDisplayValue() + ' Machine type - ' + current.variables.type_of_machine.getDisplayValue() + ' Option is - ' + current.variables.choose_one_of_the_following.sys_id.toString();
    } else {
        task.short_description = 'No Asset tag ' + current.variables.type_of_machine.getDisplayValue();
    }
    task.approval = "Approved";

 

rishabh31_0-1700553960451.png

 

I have tested this, and display conditions are working fine, but don't know why sys_id is not getting populated in the Short description, I understand that line no. 4 below mentioned part needs to be modified in such a way so that it displays sys_id of the 2nd option on Short Description of sc_task

 

current.variables.choose_one_of_the_following.sys_id.toString();

 

 I have used the below syntax but no luck yet,

 

current.variables.choose_one_of_the_following.sys_id.getValue();

 

or

 

current.variables.choose_one_of_the_following.getUniqueValue();

 

or (when using below syntax), 

current.variables.choose_one_of_the_following.sys_id;

the short description populates as below

rishabh31_0-1700554694822.png

 

Kindly help to get this resolved

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @rishabh31 

Try 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 + '';
    }
}

current.state = 2; // Set RITM as WIP
task.assignment_group.setDisplayValue('Help Desk');
if ((current.variables.choose_one_of_the_following.getDisplayValue().indexOf('To avail upgraded version of MSOffice') > -1) && (current.variables.type_of_machine.getDisplayValue().indexOf('Physical') > -1)) {
    task.short_description = 'Asset tag ID - ' + current.variables.asset_tag.getDisplayValue() + ' Machine type - ' + current.variables.type_of_machine.getDisplayValue() + ' Option is - ' + option_sys_id;
    } else {
        task.short_description = 'No Asset tag ' + current.variables.type_of_machine.getDisplayValue();
    }
    task.approval = "Approved";

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh

View solution in original post

4 REPLIES 4

Jaspal Singh
Mega Patron
Mega Patron

Hi Rishabh,

You need to GlideRecord sys_choice table to get the sys_id of the choice and then use that to populate short description.

@Jaspal Singh Sir, could you pls help with script

AnveshKumar M
Tera Sage
Tera Sage

Hi @rishabh31 

Try 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 + '';
    }
}

current.state = 2; // Set RITM as WIP
task.assignment_group.setDisplayValue('Help Desk');
if ((current.variables.choose_one_of_the_following.getDisplayValue().indexOf('To avail upgraded version of MSOffice') > -1) && (current.variables.type_of_machine.getDisplayValue().indexOf('Physical') > -1)) {
    task.short_description = 'Asset tag ID - ' + current.variables.asset_tag.getDisplayValue() + ' Machine type - ' + current.variables.type_of_machine.getDisplayValue() + ' Option is - ' + option_sys_id;
    } else {
        task.short_description = 'No Asset tag ' + current.variables.type_of_machine.getDisplayValue();
    }
    task.approval = "Approved";

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh

Thank you @AnveshKumar M Sir, Understanding the script and it works amazingly. marked response correct and helpful.