Passing Variables to Task Description Field in a workflow

aac31246
Tera Contributor

Hi all, 

 

I've been attempting to pass variables from a request item to the description field in the sc task. The issue i'm facing is that it is only returning the one variable into the field. below is the code that i am inserting into the description field of the task. Can anybody advise as to why this is occurring? 

 

var SysID = fd_data.trigger.request_item.sys_id;

var requestSys_id=SysID;

var item = new GlideRecord("sc_req_item");  

item.addQuery("sys_id", requestSys_id);  

item.query();  

if (item.next())

{    

var var_own = new GlideRecord('sc_item_option_mtom');    

var_own.addQuery('request_item', item.sys_id);        

var_own.orderBy('sc_item_option.item_option_new.order');    

var_own.query();    

while (var_own.next()){            

return(var_own.sc_item_option.item_option_new.question_text + ": " + eval('item.variable_pool.'+var_own.sc_item_option.item_option_new.name+'.getDisplayValue()') + "\n");      

 }    

}

1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hi @aac31246,

 

Instead of populating the description field, have you considered displaying the variables in the Catalog Task form?
If so, you can use the Create Catalog Task Flow Action. e.g.

JamesChun_0-1714556706869.png

 

If you must use the script, you can modify it to something like below (haven't tested it, hope it works)

var output = "";
var var_own = new GlideRecord('sc_item_option_mtom');

var_own.addQuery('request_item', fd_data.trigger.request_item.sys_id.toString());

var_own.orderBy('sc_item_option.item_option_new.order');

var_own.query();

while (var_own.next()) {

    output += var_own.sc_item_option.item_option_new.question_text + ": " + eval('item.variable_pool.' + var_own.sc_item_option.item_option_new.name + '.getDisplayValue()') + "\n";
}

return output;

 

Since you were returning the value within the While loop, you are not iterating through all of the GlideRecords.

 

Cheers

View solution in original post

2 REPLIES 2

James Chun
Kilo Patron

Hi @aac31246,

 

Instead of populating the description field, have you considered displaying the variables in the Catalog Task form?
If so, you can use the Create Catalog Task Flow Action. e.g.

JamesChun_0-1714556706869.png

 

If you must use the script, you can modify it to something like below (haven't tested it, hope it works)

var output = "";
var var_own = new GlideRecord('sc_item_option_mtom');

var_own.addQuery('request_item', fd_data.trigger.request_item.sys_id.toString());

var_own.orderBy('sc_item_option.item_option_new.order');

var_own.query();

while (var_own.next()) {

    output += var_own.sc_item_option.item_option_new.question_text + ": " + eval('item.variable_pool.' + var_own.sc_item_option.item_option_new.name + '.getDisplayValue()') + "\n";
}

return output;

 

Since you were returning the value within the While loop, you are not iterating through all of the GlideRecords.

 

Cheers

aac31246
Tera Contributor

Thanks James, that's exactly what the issue was the return being in the while loop.