- 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 05:48 AM
I tried the below code, but the event is not trigerring
var gr = new GlideRecord('sys_import_set_run');
gr.addQuery('set', source.sys_import_set);
gr.query();
if(gr.next()){
if((gr.state == 'complete') && (gr.total > '0')){
gs.eventQueue("sn_customerservice.branch.alldata", import_set, import_set.sys_id, import_set.number);
}
else if((gr.state == 'complete_with_errors') || (gr.total == '0')){
gs.eventQueue("sn_customerservice.branch.info.failure", import_set, import_set.sys_id, import_set.number);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 06:22 AM
Hi,
the total field is integer so you need to use integer during comparison
remove quotes around 0 and try
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var gr = new GlideRecord('sys_import_set_run');
gr.addQuery('set', source.sys_import_set);
gr.query();
if(gr.next()){
if((gr.state == 'complete') && (gr.total > 0)){
gs.eventQueue("sn_customerservice.branch.alldata", import_set, import_set.sys_id, import_set.number);
}
else if((gr.state == 'complete_with_errors') || (gr.total == 0)){
gs.eventQueue("sn_customerservice.branch.info.failure", import_set, import_set.sys_id, import_set.number);
}
}
})(source, map, log, target);
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 06:49 AM
Hello Ali,
As ankur already mentioned, the total is integer, so don't use quotes.
Also before the conditions, put gs.log("state is "+gr.state); to debug
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 07:00 AM
yes, I tried.. the logs for the state is showing 'running'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 07:16 AM
Is this code written under onComplete transform event script?