Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Triggering event via fix script

Abdul Azeem1
Tera Contributor

Hey Team,

Good day!!

I am planning to fire the event via fix script to trigger the notification for cases opened. So I just wanted to know will there be any issues with this approach. 

1 ACCEPTED SOLUTION

As I mentioned always run the script for few records to test it

try this

var grCase = new GlideRecord("sn_customerservice_case");
grCase.addEncodedQuery("sys_created_on>=javascript:gs.dateGenerate('2022-02-02','16:36:51')^sys_created_on<=javascript:gs.dateGenerate('2022-02-08','01:32:11')");
grCase.setLimit(5);
grCase.query();
while(grCase.next()){

	var grEmail = new GlideRecord("sys_email");
	grEmail.addQuery("subject","LIKE",grCase.number);
	grEmail.addQuery("recipients","!=", grCase.contact.email);
	grEmail.addQuery("recipients","!=", grCase.assigned_to.email);
	grCase.query();
	
	// use valid if condition
	
	if(grEmail.getRowCount() == 0){
		gs.eventQueue('event_for_email_reprocess', grCase, "","");
	}


}

Regards
Ankur

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

View solution in original post

9 REPLIES 9

Hi,

the above code is just deleting the events and should be fine

Regards
Ankur

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

var grCase = new GlideRecord("sn_customerservice_case");
grCase.addEncodedQuery("sys_created_on>=javascript:gs.dateGenerate('2022-02-02','16:36:51')^sys_created_on<=javascript:gs.dateGenerate('2022-02-08','01:32:11')");
grCase.query();
while(grCase.next()){

var grEmail = new GlideRecord("sys_email");
grEmail.addQuery("subject","LIKE",grCase.number);
grEmail.addQuery("recipients","!=", grCase.contact.email);
grEmail.addQuery("recipients","!=", grCase.assigned_to.email);

if(grEmail.next()==0){

gs.eventQueue('event_for_email_reprocess', grCase, "","");
}


}

 

The above script i ran in fixed script but tons of events got generated and still the events are generating. I deleted the event and disabled the notification but still the events are generating. I also tried by killing the All active transaction but no luck.

As I mentioned always run the script for few records to test it

try this

var grCase = new GlideRecord("sn_customerservice_case");
grCase.addEncodedQuery("sys_created_on>=javascript:gs.dateGenerate('2022-02-02','16:36:51')^sys_created_on<=javascript:gs.dateGenerate('2022-02-08','01:32:11')");
grCase.setLimit(5);
grCase.query();
while(grCase.next()){

	var grEmail = new GlideRecord("sys_email");
	grEmail.addQuery("subject","LIKE",grCase.number);
	grEmail.addQuery("recipients","!=", grCase.contact.email);
	grEmail.addQuery("recipients","!=", grCase.assigned_to.email);
	grCase.query();
	
	// use valid if condition
	
	if(grEmail.getRowCount() == 0){
		gs.eventQueue('event_for_email_reprocess', grCase, "","");
	}


}

Regards
Ankur

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

Perfect It works. Thank you Ankur:)

One query will be there any issue if I used getRowCount in production?

you should always test fix script in lower instances first and then run the actual one in production

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