Variable substitution showing backend value instead of display value in Catalog Task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
I am facing an issue with variable substitution in a ServiceNow Catalog Task. When using ${variables.primary_impacted_business_line_2}, it is returning the backend value instead of the display value in the Task Name.
I also tried using methods like getDisplayValue, but they do not seem to work in this context.
Has anyone encountered this before or found a way to display the actual label instead of the stored value?
Any suggestions or best practices would be appreciated. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Try with this:
1: Create an Email Script
- Navigate to System Policy > Email > Email Scripts.
- Click New.
- Set the Name (e.g., sctask_variables).
(function runMailScript(current, template, email, email_action, event) {
var ritm = current.request_item.getRefRecord();
var variables = ritm.variables.getElements();
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if (value && label =='primary_impacted_business_line_2') // update variable Question properly
{
template.print(label + ": " + value + "<br/>");
}
}
})(current, template, email, email_action, event);
2: Add to Notification
- Open your Notification record.
- In the Message field, call the email script using this syntax:
${mail_script:sctask_variables}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti