email script that includes an "TO" when email is triggered by an update

Peter Williams
Kilo Sage

good day,

i am trying to figure out how to script in a "TO: email address for the email notifications when a SC_REQ_ITEM gets updated.

Base on the Location the TO email address will be different

 

i have this but doesnt seem to work

 

if (revised == 'Yes') {
if (rushPay == 'Yes') {
email.subject = 'RUSH PAYMENT ' + approvedStatus + ': ' + expenseType + ' - ' + number + '[Revised]';
if (stage == 'fulfillment') {
if (location == 'Toronto') {
email.addAddress('to', 'Ip@something.com', 'Invoice Processing');

}
}
} else {
email.subject = approvedStatus + ': ' + expenseType + ' - ' + number + '[Revised]';
if (stage == 'fulfillment') {
if (location == 'Toronto') {
email.addAddress('to', 'Ip@something.com', 'Invoice Processing');
}
}
}
} else if (revised == 'No') {
if (rushPay == 'Yes') {
email.subject = 'RUSH PAYMENT ' + approvedStatus + ': ' + expenseType + ' - ' + number;
} else {
email.subject = approvedStatus + ': ' + expenseType + ' - ' + number;
}
}

1 ACCEPTED SOLUTION

@Peter Williams 

 

-> Create a new BR, say After- Update

-> In the condition select "Item IS ItemName"

-> In the script section -> mention your all the script which you mentioned above

-> Create a new event in event registry

-> Update your email notification to trigger it using event and check the checkBox as "parm1 contains recipients"

->trigger the event in BR using gs.eventQueue('Name_of_event',current,'RECIPIENTS DETAILS');

forexample:

if(condition. == "1"){

gs.eventQueue('Name_of_event',current,'RECIPIENTS DETAILS1');

}else{

gs.eventQueue('Name_of_event',current,'RECIPIENTS DETAILS2');

}

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

View solution in original post

4 REPLIES 4

Prince Arora
Tera Sage
Tera Sage

@Peter Williams 

 

Can't you create a Business Rule on the 'sc_req_item' table, specify your catalog item in the condition, and trigger an event in the script section of the Business Rule? You can pass the recipients as event parameters and capture them in ServiceNow.

Alternatively, if your catalog item has a workflow, you can trigger the event from there and pass the recipients from the workflow.

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

how would you suggest the BR way of doing it?

@Peter Williams 

 

-> Create a new BR, say After- Update

-> In the condition select "Item IS ItemName"

-> In the script section -> mention your all the script which you mentioned above

-> Create a new event in event registry

-> Update your email notification to trigger it using event and check the checkBox as "parm1 contains recipients"

->trigger the event in BR using gs.eventQueue('Name_of_event',current,'RECIPIENTS DETAILS');

forexample:

if(condition. == "1"){

gs.eventQueue('Name_of_event',current,'RECIPIENTS DETAILS1');

}else{

gs.eventQueue('Name_of_event',current,'RECIPIENTS DETAILS2');

}

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

worked like a charm thank you