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.

Why my event is in Error state in Sytem Log after beeing fired ?

wakespirit
Kilo Guru

Dear all,

I have the following script in a scheduleJob :

//Build record object on asset table
var gr = new GlideRecord('alm_asset');
//Append the querry to generate the view record based on condition
gr.addEncodedQuery('u_send_record_to_mail=true');
gr.query();

//If tehre is at least one records, we fire the event
if(gr.getRowCount() > 0){
	gs.eventQueue("Asset.retired.ccchange", gr);
	
	while (gr.next()) {
				
		//we reset the flag in order to avoid unneeded resend
		gr.u_send_record_to_mail = false;
		gr.update();
		
	}
}

What it does is that it collect all records with u_send_record_to_mail = true in Asset table
Then if tehre is at least 1 record, the event is fire.

Then once the event is fired, I cycle through collected records and reset to false the flag.

What when I test my script by pressing Execute now, in system log Event, I can see my event with a State=Error.

Any idea why and how can I solve this ?

regards

4 REPLIES 4

arielgritti
Mega Sage

Hello Scal

What error type? Do you can paste a screenshot?

Maybe this can help you

 

find_real_file.png

Please, mark correct or useful if I helped you
Thanks
Ariel

Hello,

I have a Notification email which is define to trig when my Event is fired.

 

STEP 1 : Notification not activated

If I set my Notification Active=false, just to test my event and then trig my event, then if I look in System Log> Event I can see my event and if I open it, it state is set to READY..

 

STEP 2 : Notification activated

When my notification is activated and define it as :
Type :EMAIL

Send When = Event fired
Event name : name of my event (same as in scrip above)

What it will contain : I simply define Subject email, and some dummy hard code text to see if mail gets send.

At this point when I start my schedule job, my Event has its STATE set to Error

see image

Any idea ?

It seems that it is link to email sending, do I have to specify some email provider configuration or stuff like this somewhere ?

 

Chuck Tomasi
Tera Patron

I've made a few minor clean up tweaks to the script below. It brings up additional questions:

  • Ensure you spelled the event name correctly
  • Ensure the event is registered in the event registry (System Policy> Events> Registry)

Note that you haven't retrieved a 'gr' record yet, so it has the value of null when the event is triggered. I've substituted a null for the GlideRecord argument (2).

//Build record object on asset table
var gr = new GlideRecord('alm_asset');
//Append the querry to generate the view record based on condition
gr.addQuery('u_send_record_to_mail', true);
gr.query();

//If there is at least one record, we fire the event
if(gr.hasNext()){
	gs.eventQueue("Asset.retired.ccchange", null, '', '');
	
	while (gr.next()) {
				
		//we reset the flag in order to avoid unneeded resend
		gr.u_send_record_to_mail = false;
		gr.update();
		
	}
}

Hi chuck,

let me know if I am doing wrong ..

Based on your initial question, yes all is in place

 

STEP 1 :

Now based on the parameter NULL for the event, I though 'gr' object was containing records

 

I am new to this area, my goal is tor trig an event as about and then retrieve collected all records with u_send:record_to_mail =true in order to write them in an email body.

Does it mean I have to pass those match records as part of the Event param ?

If yes I can I send the record to the event ?

 

STEP 2 :

When my email notification trig based on my event, I need to collect those matching record from my event Object ?

 

Initialy I have made a Notification Email Script  ( seen in sample around), in order to be injected in my mail body but have no idea how this script will be executed and when .

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

    template.print("Records which has beend retired or have cost Center change. \n\n");
	var gr = new GlideRecord ("alm_asset");
	
	gr.addQuery('u_send_record_to_mail', true);
	
	gr.query();
	
        >>>>> ????? WhaT TO PLACE HERE TO COLLECT RECORDS INTO CELLS BELOW

template.print("<table border=1 boardercolor=black>");
	template.print("<tr><th align='left'>name</th><th align='left'>State</th></tr>");
	
>>>>> ????? WhaT TO PLACE HERE TO COLLECT RECORDS INTO CELLS BELOW

template.print("</table>");

})(current, template, email, email_action, event);

 

Any help, could not find full sample and get confused