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

Hi,

if you have put this in onComplete then it should not show state as Running

Ensure you create onComplete Transform Script only

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

Regards
Ankur

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

Yes its in oncomplete script only

Hi,

Possibly the last record taking more time to run;

Did you verify the last record got processed when this script ran?

Regards
Ankur

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

Hi,

to be on safer side you can try after update BR on Transform History Table

BR: After Update

Condition: State is one of Complete/Complete with errors && current.set.data_source == 'yourDataSourceSysId'

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here

	if(current.state == 'complete' && current.total > 0){
		gs.eventQueue("sn_customerservice.branch.alldata", import_set, import_set.sys_id, import_set.number);
	}
	else if(current.state == 'complete_with_errors' || current.total == 0){
		gs.eventQueue("sn_customerservice.branch.info.failure", import_set, import_set.sys_id, import_set.number);
	}

})(current, previous);

Screenshots:

find_real_file.png

find_real_file.png

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

Regards
Ankur

 

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

I Placed a log before the event, getting the below error

 

org.mozilla.javascript.EcmaError: "import_set" is not defined.
Caused by error in sys_script.28fbe119dbd158dcb976671cd3961941.script at line 1

==> 1: (function executeRule(current, previous /*null when async*/) {
2:
3: gs.info("I am in BR1");
4: if(current.state == 'complete' && current.total > 0){