email script in email template

Vedavalli
Tera Contributor

When I'm trying to use my email script in email template
I'm getting 

Following variables are not valid or defined: ${mail_script:missing_fields_data}
Error Message
Invalid update

can I know the reason for this 

Thank you
1 ACCEPTED SOLUTION

@Vedavalli 

Thank you for marking my response as helpful.

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

12 REPLIES 12

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

    var missingFields = [];

    // Check if state is 'On Hold' (typically value 3 — confirm in your system)

    if (current.getValue('state') == '3') {

        if (!current.getValue('hold_reason')) {

            missingFields.push("On Hold Reason");

        }

        if (!current.getValue('close_notes')) {

            missingFields.push("Resolution Notes");

        }

        if (missingFields.length > 0) {

            template.print("The following mandatory fields are missing:<ul>");

            for (var i = 0; i < missingFields.length; i++) {

                template.print("<li>" + missingFields[i] + "</li>");

            }

            template.print("</ul>");

        } else {

            template.print("All mandatory fields are filled.");

        }

    } else {

        template.print("Incident is not in 'On Hold' state.");

    }

})(current, template, email, email_action, event);
 this is the script

@Vedavalli 

I used the same email script and it worked fine

AnkurBawiskar_0-1746694108271.png

 

When I click send the email goes correctly in email logs and I am able to see that in Preview Email

AnkurBawiskar_1-1746694190069.png

 

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

@Vedavalli 

Thank you for marking my response as helpful.

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