Variable substitution showing backend value instead of display value in Catalog Task

VijayKumarDodde
Tera Expert

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!

1 REPLY 1

Tanushree Maiti
Tera Patron

Hi @VijayKumarDodde 

 

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}

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti