- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 04:19 AM
Hi All,
I need to trigger email notification based on the event triggered, If we have errors in transform history then i have to trigger 'xyz' event , if if there are no errors then 'abc' event..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 09:36 AM
Hi,
So you created after update BR as per above screenshots;
please update code as below; I forgot to query Import Set table with the current Import Set and then passed the GlideRecord Object to that eventQueue()
Updated Now: Ensure you set valid recipient for the event;
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var importSet = new GlideRecord('sys_import_set');
importSet.addQuery('sys_id', current.set);
importSet.query();
if(importSet.next()){
if(current.state == 'complete' && current.total > 0){
gs.eventQueue("sn_customerservice.branch.alldata", importSet, recipient, importSet.number);
}
else if(current.state == 'complete_with_errors' || current.total == 0){
gs.eventQueue("sn_customerservice.branch.info.failure", importSet, recipient, importSet.number);
}
}
})(current, previous);
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
06-08-2020 04:34 AM
Hello,
If I understand correctly, you want to trigger a mail when all the rows have been transformed with details for all the failed rows.
1 ) Define a variable in the onStart script for the map. ((Do not encapsulate it in a function, keep it outside all functions so that other scripts can access the same).
2 ) Update the content of this variable each time you find any error in your onBefore script.
3 ) Use the same variable to pass the accumulated error data to the email notification in onComplete transform script, using gs.eventQueue() function.
If answer is helpful mark correct!
Thanks,
Pratiksha

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 04:40 AM
Hello Ali,
You can trigger an event under onComplete transform script. In this script you can do glide record like this and check
var gr = new GlideRecord("sys_import_set_row_error");
gr.addEncodedQuery("row.sys_import_set="+source.import_set+"^sys_created_onONLast 15 minutes@javascript:gs.beginningOfLast15Minutes()@javascript:gs.endOfLast15Minutes()");
gr.query();
if(gr.next()) {
//there are errors. so trigger your xyz event here
gs.eventQueue("your_xyx",gr,gs.getUserName(),gs.getUserID());
} else {
// no errors.
gs.eventQueue("other_event",gr,gs.getUserName(),gs.getUserID());
}
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 04:47 AM
Hi Asif, i need to consider Transform History where Total is also '0' , to notify that there is an error in the notification

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:22 AM
In that case, try like this
var gr = new GlideRecord("sys_import_set_row_error");
gr.addEncodedQuery("row.sys_import_set="+source.import_set+"^sys_created_onONLast 15 minutes@javascript:gs.beginningOfLast15Minutes()@javascript:gs.endOfLast15Minutes()");
gr.query();
if(gr.next()) {
//there are errors. so trigger your xyz event here
gs.eventQueue("your_xyx",gr,gs.getUserName(),gs.getUserID());
} else {
// check he total
var gr = new GlideRecord("sys_import_set_run");
if(gr.get(source.import_set)) {
if(gr.total ==0) {
//there are errors. so trigger your xyz event here
gs.eventQueue("your_xyx",gr,gs.getUserName(),gs.getUserID());
} else {
gs.eventQueue("other_event",gr,gs.getUserName(),gs.getUserID());
}
}
}
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP