scheduled reports to send to assignment group managers when the tickets are unassigned

bhanu27
Tera Expert

Scheduled reports to send to assignment group managers when the tickets are unassigned or assigned to field is empty, how can we achieve it, please help me.

2 ACCEPTED SOLUTIONS

@bhanu27 you can include this report too, follow all the steps as is except Step 3: Mail Script.

 

Copy the sys_id of your report then in Step 4: Notification replace 

${mail_script:ag_unassigned_incident_report}

 

With

 

${report:reportID:YOUR_REPORT_SYSID}

 

This will include your report as PDF attachment in the notification email.

 

Please mark my answer helpful and accept as solution if it helped you 👍

Thanks,
Anvesh

View solution in original post

@bhanu27 Who is the run as user for Scheduled Job? And check the user which you are using to test (i.e. changing the assignment group) have access to table , are there any ACL restrictions (report type ACL also).

 

And try creating a new simple report and try to insert that in the code and check, whether you are getting the same error or not?

Thanks,
Anvesh

View solution in original post

13 REPLIES 13

Hi @AnveshKumar M ,

 

Thanks for reply.

The first requirement is

I want this mail to be triggered immediately on unassigned count reaching 5 or more.

 

Second thing every Monday I need to send report irrelevant of ticket count..

 

So can you please share me script Accordingly the first requirement is my priority.

 

Thanks in advance.

Regards

Bhanu.

 

@bhanu27 

 

Try the following approach.

 

1. Create an Event in event registry

AnveshKumarM_0-1698412831026.png

 

2. Create a business rule

AnveshKumarM_1-1698412926186.png

 

AnveshKumarM_2-1698412953219.png

 

AnveshKumarM_3-1698412970834.png

 

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

	var incGr = new GlideRecord("incident");
	incGr.addQuery("assignment_group", current.assignment_group);
	incGr.addEncodedQuery("assigned_toISEMPTY");
	incGr.setLimit(11);
	incGr.query();

	if(incGr.getRowCount() >= 5){
		gs.eventQueue("incident.unassigned.count5", current, current.assignment_group);
	}

})(current, previous);

 

3. Mail Script:

AnveshKumarM_4-1698413036167.png

 

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

    var incGr = new GlideRecord("incident");
    incGr.addQuery("assignment_group", current.assignment_group);
    incGr.addEncodedQuery("assigned_toISEMPTY");
    incGr.query();

    var incidents = '<table style="width: 100%;"><tbody><tr><td class="bg1" colspan="7">Number</td><td class="bg1" colspan="7">Short Description</td></tr>';
    while (incGr._next()) {
        incidents = incidents + '<tr><td colspan="7">' + incGr.number + '</td><td colspan="7">' + incGr.short_description + '</td></tr>';
    }

    incidents = incidents + '</tbody></table>';
    template.print(incidents);

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

 

4. Notification:

 

AnveshKumarM_5-1698413076162.png

 

AnveshKumarM_6-1698413089964.png

 

AnveshKumarM_7-1698413102948.png

 

AnveshKumarM_8-1698413122585.png

 

<p>&nbsp;</p>
<style><!--
table {
font-family: cambria;
}
td.bg1{
background-color:#E2E2E3;
color:#7C427F;
font-weight: bold;
}
td.bg2{
color:black;
}
 img.bottom {
    vertical-align: text-bottom;
 }
 --></style>
<table style="width: 100%;">
<tbody>
<tr>
<td colspan="7">Dear ${assignment_group.manager},<br />
<p>${assignment_group} has more than 5 unassigned Incidents</p>
</td>
</tr>
</tbody>
</table>
<h4>Un Assigned Incidents:</h4>
<p>${mail_script:ag_unassigned_incident_report}</p>

 

5. Scheduled Job:

AnveshKumarM_9-1698413501624.png

 

var grpGr = new GlideRecord("sys_user_group");
grpGr.query("active", true);
grpGr.query();

while (grpGr.next()) {
    var incGr = new GlideRecord("incident");
    incGr.addQuery("assignment_group", grpGr.sys_id);
    incGr.addEncodedQuery("assigned_toISEMPTY");
    incGr.setLimit(6);
    incGr.query();

    if (incGr.getRowCount() >= 5) {
		incGr.next();
        gs.eventQueue("incident.unassigned.count5", incGr, incGr.assignment_group);
    }
}

 

Final Result:

AnveshKumarM_10-1698413612033.png

 

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

Thanks,
Anvesh

Hi @AnveshKumar M 

 

Really a very big thanks for your response and patience and time spent for me this is really a great thing.

But my concern is i need to send a schedule report like below to assignment group managers when the assigned to field is empty and assignment group is not empty.

 

In below screen there are some unassigned tickets for each group so i need to send this report to those respective managers with attachment 

can you please help me on it like writing a script/condition in schedule report

bhanu27_0-1698415537694.png

 

bhanu27_1-1698415763515.png

 

Thanks and Regards

Bhanu.

@bhanu27 you can include this report too, follow all the steps as is except Step 3: Mail Script.

 

Copy the sys_id of your report then in Step 4: Notification replace 

${mail_script:ag_unassigned_incident_report}

 

With

 

${report:reportID:YOUR_REPORT_SYSID}

 

This will include your report as PDF attachment in the notification email.

 

Please mark my answer helpful and accept as solution if it helped you 👍

Thanks,
Anvesh

bhanu27
Tera Expert

Hi @AnveshKumar M 

 

Thanks for the your reply and solution, really it is helpful and almost my job is done, the only small thing that is not working is, am getting null report as attachment instead of my report, and when i open my report it showing below message.

bhanu27_0-1698676872300.png

My Notification screen is as below:

bhanu27_1-1698676966775.png