Email script to show SCTASK-level variables in notification

JGuerrero0323
Tera Expert

Hi ServiceNow Community,

I’m looking for some help or guidance on how to create an email script.

What I want to achieve is to include all the variables that are shown at the SCTASK level in the email — either as a summary or in a detailed format. Basically, I’d like to replicate what the requester sees in the catalog task, so that it’s also visible in the email.

Has anyone done something similar or could point me in the right direction to script this?

Thanks in advance!

1 ACCEPTED SOLUTION

@JGuerrero0323 

yes, you can create 1 email script and use in the sc_task notification level

Then use below script to show all variables of that catalog item

It will work for any catalog item

Note: you will have to enhance this for printing MRVS

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    template.print('RITM Variables: <br/>');
    var ritmRecord = current.request_item.getRefRecord();
    var variables = ritmRecord.variables.getElements();
    for (var i = 0; i < variables.length; i++) {
        var question = variables[i].getQuestion();
        var label = question.getLabel();
        var value = question.getDisplayValue();
        if (label != '') {
            template.space(4);
            template.print('  ' + label + " = " + value + "<br/>");
        }
    }

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

@JGuerrero0323 

yes, you can create 1 email script and use in the sc_task notification level

Then use below script to show all variables of that catalog item

It will work for any catalog item

Note: you will have to enhance this for printing MRVS

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    template.print('RITM Variables: <br/>');
    var ritmRecord = current.request_item.getRefRecord();
    var variables = ritmRecord.variables.getElements();
    for (var i = 0; i < variables.length; i++) {
        var question = variables[i].getQuestion();
        var label = question.getLabel();
        var value = question.getDisplayValue();
        if (label != '') {
            template.space(4);
            template.print('  ' + label + " = " + value + "<br/>");
        }
    }

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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