- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 12:34 AM
Hello,
I am trying to retrieve the values of the variables in the catalog task form. I am using the flowing script, but instead of returning the values of the variables, it is giving me something like an ID (as shown in the picture).
script:
the main variable is:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 01:26 AM
Hi @MaramA ,
Please try the below code:
(function runMailScript(current, template, email, email_action, event) {
// Retrieve and format the catalog task variables for display
var formattedVariables = getTaskVariableResponse(current);
template.print(formattedVariables);
})(current, template, email, email_action, event);
function getTaskVariableResponse(taskGr) {
var formattedList = [];
if (taskGr.request_item) {
var optionRecord = new GlideRecord('sc_item_option_mtom');
optionRecord.addQuery('request_item', taskGr.request_item.sys_id);
optionRecord.query();
while (optionRecord.next()) {
var displayName = optionRecord.sc_item_option.item_option_new.getDisplayValue();
var value1 = optionRecord.sc_item_option.value;
var sysUser = new GlideRecord('sys_user');
if(sysUser.get(value1)){
var value = sysUser.name;
}
// Ensure that both display name and value are not null before appending
if (displayName !== null && value !== null) {
formattedList.push(displayName + ': ' + value);
}
}
}
return formattedList.join('<br>');
}
Please mark this response as correct or helpful if it assisted you with your question.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 01:26 AM
Hi @MaramA ,
Please try the below code:
(function runMailScript(current, template, email, email_action, event) {
// Retrieve and format the catalog task variables for display
var formattedVariables = getTaskVariableResponse(current);
template.print(formattedVariables);
})(current, template, email, email_action, event);
function getTaskVariableResponse(taskGr) {
var formattedList = [];
if (taskGr.request_item) {
var optionRecord = new GlideRecord('sc_item_option_mtom');
optionRecord.addQuery('request_item', taskGr.request_item.sys_id);
optionRecord.query();
while (optionRecord.next()) {
var displayName = optionRecord.sc_item_option.item_option_new.getDisplayValue();
var value1 = optionRecord.sc_item_option.value;
var sysUser = new GlideRecord('sys_user');
if(sysUser.get(value1)){
var value = sysUser.name;
}
// Ensure that both display name and value are not null before appending
if (displayName !== null && value !== null) {
formattedList.push(displayName + ': ' + value);
}
}
}
return formattedList.join('<br>');
}
Please mark this response as correct or helpful if it assisted you with your question.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 01:37 AM
Thank you very much, it works perfectly