Requested Notification: Application Development incident count

Mimi Edet
Tera Guru

As the manager of the Application Development group, I would like to receive an email every Monday with the number of active Incidents assigned to me at the start of the week so that I can prioritize and balance team workload

[Interview knowledge transfer: A previous engineer has already started development on this. However they could not get it to work. See the items below
- Scheduled job: Application Development Weekly Notification
- Notification: Weekly Notification - Application Dev
- Mail script: app_dev_summary

 

Acceptance Criteria: 

I will know this is complete when I receive a weekly email that matches this format:

 

Recipient: Application Development manager

Subject: Weekly summary – [Date email sent] – Application Development Incidents

 

Body:

Hello [Group manager’s name],

 

This week your group has [number of active incidents] active Incidents. See below for the list of incidents.

[List of incidents, each number should link to the related incident] 

 

Please I need help with this requirement.

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage

Hello @Mimi Edet 

You can use the following approach to continue with work left by the previous engineer.

 

1. Create an Event in Registry:

 

AnveshKumarM_0-1728452789259.png

 

2. Create Scheduled Script Job: Try to adjust Time Zone and Time as per your need.

 

AnveshKumarM_1-1728452843733.png

 

var incGr = new GlideRecord('incident');
//Add query for state in New, In progrees and OnHold and Assignment group is "Applciation Development", You can change sys_id of assignment group according to group sys_id in your insatnce.
incGr.addEncodedQuery("assignment_group=0a52d3dcd7011200f2d224837e6103f2^stateIN1,2,3");
incGr.setLimit(1);
incGr.query();
if(incGr._next()){
	var group_manager = incGr.assignment_group.manager + "";
	if(!gs.nil(group_manager)){
		gs.eventQueue('custom.incident.active.weekly_report', incGr, group_manager, "");
	}
}

 

3. Create Email Script: I have used ordered list for Incidents list, you can even use the table format as presented by @vermaamit16 

 

AnveshKumarM_2-1728452921865.png

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

	var inc_list = "<ol>";
	var instance_url = gs.getProperty('glide.servlet.uri') + '/';
	var count = 0;
    var incGr = new GlideRecord('incident');
    //Add query for state in New, In progrees and OnHold and Assignment group is "Applciation Development", You can change sys_id of assignment group according to group sys_id in your insatnce.
    incGr.addEncodedQuery("assignment_group=0a52d3dcd7011200f2d224837e6103f2^stateIN1,2,3");
    incGr.query();
    while (incGr._next()) {
		count++; //Instead of the counter you can use GlideAggregate / getRowCount
        inc_list = inc_list + "<li><a href='" + incGr.getLink(true) + "'>" + incGr.getValue('number') + "</a> - " + incGr.getValue('short_description') + "</li>";
    }
	inc_list = inc_list + "</ol>";
	
	email.subject = "Weekly summary -" + new GlideDateTime().getDisplayValue() + " Application Development Incidents" ;

	template.print("<p>This week your group has " + count + " active incidents. See below for the list of incidents.</p>");

	template.print(inc_list);
})(current, template, email, email_action, event);

 

4. Create Notification:

 

AnveshKumarM_3-1728452976868.png

 

When to Send:

 

AnveshKumarM_4-1728453001028.png

Who will receive:

AnveshKumarM_5-1728453019680.png

Content:

AnveshKumarM_6-1728453037941.png

 

 

And here is the final output:

AnveshKumarM_7-1728453109629.png

 

AnveshKumarM_8-1728453129773.png

 

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

 

View solution in original post

3 REPLIES 3

PrashantLearnIT
Tera Sage

Hi @Mimi Edet 

 

Steps to Complete the Requirement:

  1. Scheduled Job: Application Development Weekly Notification

    • Check if the job is scheduled correctly:
      • Ensure that the job is set to run every Monday.
      • Verify that it’s set to call the app_dev_summary mail script.
    • Review the script logic: Ensure it’s fetching incidents assigned to the group manager at the start of the week.
  2. Mail Script: app_dev_summary

    • Data Gathering:

      • Ensure the script is correctly retrieving the number of active incidents assigned to the Application Development group.
      • Use a query like:
    • var groupManager = 'manager_id'; // Replace with the correct manager ID
      var gr = new GlideRecord('incident');
      gr.addQuery('assignment_group.name', 'Application Development');
      gr.addQuery('active', true);
      gr.query();
      var count = gr.getRowCount();

 

    • This script should gather both the count of incidents and the details (including links) to display in the email body.
  • Generate Links to Incidents: Each incident should have a clickable link that leads to the related record. You can do this by creating URLs like:

var incidentLink = '<a href="' + gs.getProperty('glide.servlet.uri') + 'incident.do?sys_id=' + gr.sys_id + '">' + gr.number + '</a>';

 

Formatting the Email:

  • Populate the subject line with the current date:

var dateSent = new GlideDateTime().getLocalDate().toString();
template.subject = 'Weekly summary – ' + dateSent + ' – Application Development Incidents';

 

In the body, loop through incidents and build the list:

var emailBody = 'Hello ' + groupManagerName + ',<br><br>';
emailBody += 'This week your group has ' + count + ' active Incidents. See below for the list of incidents:<br>';

while (gr.next()) {
var incidentLink = '<a href="' + gs.getProperty('glide.servlet.uri') + 'incident.do?sys_id=' + gr.sys_id + '">' + gr.number + '</a>';
emailBody += incidentLink + '<br>';
}

emailBody += '<br>Please review and prioritize.<br>';
template.body = emailBody;

 

 

  • Notification: Weekly Notification - Application Dev

    • Configure Recipient:
      • Ensure the recipient is correctly set as the Application Development manager (or dynamically fetched if needed).
    • Test Notification: Use a test email address initially to ensure the email content and format are correct.
  • Test and Debug:

    • Trigger the scheduled job manually to test the email.
    • Check the system logs to ensure there are no errors related to the script, scheduled job, or notification setup.

 

 

 

vermaamit16
Kilo Patron

Hi @Mimi Edet 

 

You can do it with a Flow as well. Refer below steps -

 

1. Create a flow with trigger set to Weekly - Monday. Set the time to trigger as per your requirement :

AmitVerma_0-1728450781753.png

2. Create a flow variable to hold the HTML string and set the initial HTML to form the table structure -

AmitVerma_1-1728450851545.png

 

AmitVerma_2-1728450867383.png

<html>
<head>
<style>
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;
}
</style>
</head>
<body>
<h2>Open Incidents</h2>
<table>
  <tr>
    <th>Incident Number</th>
    <th>Link to Incident</th>
  </tr>

 

3. Get All the incidents assigned to you using Look Up records. Please change the Assigned To to your user -

AmitVerma_3-1728451047736.png

 

4. Iterate through the assigned to incidents using for each item. Within the for each scope , we will set the flow variable again to append the table data html to our existing html string -

 

AmitVerma_4-1728451103682.png

AmitVerma_5-1728451160775.png

var html = fd_data.flow_var.openincidentshtml;
var instanceURL = gs.getProperty('glide.servlet.uri')';
var incidentLink = '<a href="' + instanceURL + 'incident.do?sys_id=' + fd_data._3__for_each.item.sys_id + '">' + fd_data._3__for_each.item.number + '</a>';
html+='<tr><td>'+fd_data._3__for_each.item.number+'</td><td>'+incidentLink+'</td></tr>';
return html;

 

5. Next, we will set the flow variable again outside the for each scope to terminate the HTML string -

AmitVerma_6-1728451300892.png

 

var html = fd_data.flow_var.openincidentshtml;
html+='</table></body></html>';
return html;

 

6. Finally, we will make use of Send Email action. You can change the to email ID to your email ID.

AmitVerma_7-1728451411006.png

 

AmitVerma_8-1728451430695.png

Output -

 

AmitVerma_9-1728451495608.png

 

AmitVerma_10-1728451515597.png

 

Thanks and Regards

Amit Verma

AnveshKumar M
Tera Sage

Hello @Mimi Edet 

You can use the following approach to continue with work left by the previous engineer.

 

1. Create an Event in Registry:

 

AnveshKumarM_0-1728452789259.png

 

2. Create Scheduled Script Job: Try to adjust Time Zone and Time as per your need.

 

AnveshKumarM_1-1728452843733.png

 

var incGr = new GlideRecord('incident');
//Add query for state in New, In progrees and OnHold and Assignment group is "Applciation Development", You can change sys_id of assignment group according to group sys_id in your insatnce.
incGr.addEncodedQuery("assignment_group=0a52d3dcd7011200f2d224837e6103f2^stateIN1,2,3");
incGr.setLimit(1);
incGr.query();
if(incGr._next()){
	var group_manager = incGr.assignment_group.manager + "";
	if(!gs.nil(group_manager)){
		gs.eventQueue('custom.incident.active.weekly_report', incGr, group_manager, "");
	}
}

 

3. Create Email Script: I have used ordered list for Incidents list, you can even use the table format as presented by @vermaamit16 

 

AnveshKumarM_2-1728452921865.png

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

	var inc_list = "<ol>";
	var instance_url = gs.getProperty('glide.servlet.uri') + '/';
	var count = 0;
    var incGr = new GlideRecord('incident');
    //Add query for state in New, In progrees and OnHold and Assignment group is "Applciation Development", You can change sys_id of assignment group according to group sys_id in your insatnce.
    incGr.addEncodedQuery("assignment_group=0a52d3dcd7011200f2d224837e6103f2^stateIN1,2,3");
    incGr.query();
    while (incGr._next()) {
		count++; //Instead of the counter you can use GlideAggregate / getRowCount
        inc_list = inc_list + "<li><a href='" + incGr.getLink(true) + "'>" + incGr.getValue('number') + "</a> - " + incGr.getValue('short_description') + "</li>";
    }
	inc_list = inc_list + "</ol>";
	
	email.subject = "Weekly summary -" + new GlideDateTime().getDisplayValue() + " Application Development Incidents" ;

	template.print("<p>This week your group has " + count + " active incidents. See below for the list of incidents.</p>");

	template.print(inc_list);
})(current, template, email, email_action, event);

 

4. Create Notification:

 

AnveshKumarM_3-1728452976868.png

 

When to Send:

 

AnveshKumarM_4-1728453001028.png

Who will receive:

AnveshKumarM_5-1728453019680.png

Content:

AnveshKumarM_6-1728453037941.png

 

 

And here is the final output:

AnveshKumarM_7-1728453109629.png

 

AnveshKumarM_8-1728453129773.png

 

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