- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 02:19 AM
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");
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 02:48 AM
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 02:48 AM
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 02:52 AM
Thanks James, that's exactly what the issue was the return being in the while loop.