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!

3 REPLIES 3

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

@Tanushree Maiti  

My issue is not related to Notifications or email templates. I am looking for a solution for an Advanced Catalog Task where the Task Name is not displaying the variable's display value and is showing the backend value instead and this advanced catalog task created using 'Catalog Builder'. Updating the Catalog Task Definition and using variable substitution has not resolved the issue. Has anyone encountered this specifically with Advanced Catalog Tasks?

Ankur Bawiskar
Tera Patron

@VijayKumarDodde 

how is the catalog task created? via flow or workflow?

share screenshots of where you are using that

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader