- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2020 08:17 AM
Hi Team,
I have a requirement to trigger a notification.
The notification is created on 'Sysapproval_approver' table.
I have to send this notification to a email id which is present in the 'sc_req_item' form. Variable name in sc_req_item is : 'local_procurement'.
So my notification is getting fired based on condition, it is having the RITM number, how I can write email script to get the value of variable 'local_procurement' and pass this via email script made calling on sysapproval_approver table to trigger the notification to that email id(local_procurement).
Please suggest.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 09:52 PM
Hi Geeta,
in workflow you can use wait for timer activity for waiting and then sending email
You can include schedule as well for excluding weekends
If you are stuck inform the issue.
Please consider marking appropriate reply as ✅Correct & 👍Helpful.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2020 08:28 AM
Hi Geeta,
Sample script as below (untested). Mailscript: getprocurementid
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var procurementid;
var getid=new GlideRecord('sc_req_item');
getid.addQuery('sys_id',current.sysapproval);
getid.query();
if(getid.next())
{
procurementid=getid.variables.local_procurment; //local_procurement being variablename
gs.log('Procurement ID', procurementid);//should give you address stored in local_procurement variable
email.addAddress('CC',procurement);
}
})(current, template, email, email_action, event);
Then, call the mail script above in notification in format ${mail_script:getprocurementid}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2020 08:54 AM
Hi Jaspal,
Thanks for the reply.
However it is going inside the if loop but not fetching the value of variable procurement id in sc_re_item. value of 'Procurement ID ' is coming as 'undefined' in logs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2020 09:06 AM
Hi Geeta,
I believe you want the email to be sent to user belonging to variable local_procurement
the variable contains email address
Since your notification is triggering on the condition; it cannot be sent to that user as you cannot select that variable in the whom to send option.
You cannot select variable from here
The best way is going to be to use the event driven notification and pass the recipient as a
parameter then use one of these checkboxes for Event parm1 or event parm2 contains recipient.
Please use event queue approach
1) create event on RITM or Approval table
2) associate email notification with that newly created event
3) trigger event via after Insert BR on sysapproval_approver table
BR Condition: It should trigger event only for your catalog item and not for others
Sample script here:
var ritm = current.sysapproval;
var ritmRec = new GlideRecord('sc_req_item');
ritmRec.get(ritm);
if(ritmRec.cat_item == 'your catalog item sysId'){
gs.eventQueue('event_name', ritmRec, ritmRec.variables.local_procurement);
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2020 09:26 AM
Hi Ankur,
Thanks for the response.
The notification is created on 'sysapproval_approver' table and is getting triggered from flow designer. It is having the RITM number value but in the email script I am not able to get the 'Local_procurement' variable value(Which is present on 'sc_req_item' form)
Logic I am trying is to get the value of 'local_procurement' in email script and to use it in the notification to target the recipient.
--
Thanks,
Geeta