Email Scripts

MohdF
Tera Contributor

Hi everyone,

 

I am trying to create an email notification and the conditions are these -

* when incident's state is in progress and the assigned to is not empty

then I want to send an email to the "assigned to" user with their manager in cc

I am trying to this with email script and my email script is this...

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var assignedTo = current.assigned_to;
	var manageremail = current.assignedTo.manager.email;

    email.addAddress('to', assignedTo);
	email.addAddress('cc', manageremail);

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

I am not sure if the script is correct or not but I am trying and my "notification: what will it contain" email body is this...

${mail_script:in progess state}

 

Hello ${assigned_to.first_name},

${number} state is in progress.

Servicenow Team

 

Please help.

 

Thank you

 

4 REPLIES 4

HIROSHI SATOH
Mega Sage

I hope this helps.

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

    var assignedTo = current.assigned_to;
    if (assignedTo && assignedTo.manager && assignedTo.manager.email) {
        var managerEmail = assignedTo.manager.email;
        email.addAddress('cc', managerEmail);
    }

    email.addAddress('to', assignedTo);

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

mail Body:

Hello ${assigned_to.first_name},

The incident (${current.number}) is now in ${current.state.getDisplayValue()} state.

Servicenow Team






 

Nope, It did not work as well

 

Thanks

Sandeep Rajput
Tera Patron
Tera Patron

@MohdF Please try the following.

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var assignedTo = current.assigned_to.toString();
	var manageremail = current.assignedTo.manager.email.toString();

    email.addAddress('to', assignedTo);
	email.addAddress('cc', manageremail);

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

Hi Sandeep, 

I did that but it is not triggering the email just like before.

 

Thanks