Email script

Sironi
Kilo Sage

Hi,

someone help on incident script,

send  incident details list to assigned to if incident state is OnHold on single notification .

ex: DavidLoo hasbeen assigned to 10-incidents , in 10-incidents there are 7 incidents have state -onhold. so DavidLoo should receive 7-incident details (number, shortdescription, caller , priority)  in a single email.

i tried with below script, it is getting single incident details, how to get all in single email.

template.print("number :"+"${number}\n");

template.print("number :"+"${priority}\n");

template.print("number :"+"${caler_id}\n");

template.print("number :"+"${short_description}\n");

 

1 ACCEPTED SOLUTION

Hi,

I just updated the job code

It triggered 3 emails to 3 different users

Email triggered to David Loo has incident info Assigned to David Loo

Email triggered to Rosie Mathews has incident info Assigned to Rosie Mathews

Email triggered to Fred Luddy has incident info Assigned to Fred Luddy

Now the only thing you need to check is why it didn't send email to other 6 users

Updated Job Code:

sendEmail();

function sendEmail() {

	var gr = new GlideAggregate("incident");
	gr.addAggregate("COUNT");
	gr.addEncodedQuery('active=true^assigned_toISNOTEMPTY');
	gr.groupBy("assigned_to");
	gr.query();
	while(gr.next()) {
		var user = gr.assigned_to;
		var incRec = new GlideRecord('incident');
		incRec.get('assigned_to', user);
		gs.eventQueue('test_list', incRec, incRec.assigned_to, incRec.assigned_to);
	}
}

Regards
Ankur

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

View solution in original post

46 REPLIES 46

Sure, please help me how to fix this issue.

@Sironi 

please try this and check

sendEmail();

function sendEmail(){

var arr = [];

var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^assigned_toISNOTEMPTY');
gr.query();
while(gr.next()){
arr.push(gr.assigned_to.toString());
}

var arrayUtil = new ArrayUtil();
var uniqueArray = arrayUtil.unique(arr);

var inc = new GlideRecord('incident');
inc.addQuery('assigned_to', 'IN', uniqueArray);
inc.setLimit(arr.length);
inc.query();
while(inc.next()){

gs.eventQueue('test-list', inc, gs.getUserID(), gs.getUserName());

}

}

Regard
Ankur

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

@Sironi 

Did you got a chance to check on the solution provided to resolve your query?

Let me know if that answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

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

@Ankur Bawiskar 

Thanks for your reply, i tested your script. but unfortunately it is not working . can you test it in my PDI incase if you want ?

Result : old issue repeated . 

find_real_file.png

@Sironi 

Please share instance url, some admin user credentials

Regards
Ankur

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