Need to trigger 2 events in On-complete Transform Map scripts

Mohammed Hyder2
Kilo Expert

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..

 

1 ACCEPTED SOLUTION

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

17 REPLIES 17

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);
}

}

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

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

yes, I tried.. the logs for the state is showing 'running'

Is this code written under onComplete transform event script?