- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 07:02 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 10:54 PM
Hello @Mimi Edet
You can use the following approach to continue with work left by the previous engineer.
1. Create an Event in Registry:
2. Create Scheduled Script Job: Try to adjust Time Zone and Time as per your need.
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 @Amit Verma
(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:
When to Send:
Who will receive:
Content:
And here is the final output:
Please mark my answer helpful 👍 and accept as a solution ✔️ if it helped you.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 09:06 PM
Hi @Mimi Edet
Steps to Complete the Requirement:
-
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.
- Check if the job is scheduled correctly:
-
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.
- Configure Recipient:
-
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.
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 10:25 PM
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 :
2. Create a flow variable to hold the HTML string and set the initial HTML to form the table structure -
<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 -
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 -
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 -
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.
Output -
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 10:54 PM
Hello @Mimi Edet
You can use the following approach to continue with work left by the previous engineer.
1. Create an Event in Registry:
2. Create Scheduled Script Job: Try to adjust Time Zone and Time as per your need.
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 @Amit Verma
(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:
When to Send:
Who will receive:
Content:
And here is the final output:
Please mark my answer helpful 👍 and accept as a solution ✔️ if it helped you.
Anvesh