How to create repeated incident report.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2023 09:46 PM
The number of identical incidents logged within a specific time frame.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2023 09:58 PM
HI @Anusha420 ,
I trust you are doing great.
- Create a new table in ServiceNow to store the incident details. Let's call it "Incident".
- Add fields to the "Incident" table to capture relevant information such as incident number, description, logged date, and any other required details.
- Configure a UI action or a scheduled job to run at regular intervals to check for identical incidents within the specified time frame.
- Use the ServiceNow GlideRecord API to query the "Incident" table and count the number of identical incidents based on specific criteria.
Here's an example of the code you can use to implement this solution:
// Define the start and end dates of the time frame
var startDate = gs.dateGenerate('2023-06-01', 'startOfDay'); // Replace with the desired start date
var endDate = gs.dateGenerate('2023-06-30', 'endOfDay'); // Replace with the desired end date
// Create a new GlideRecord instance for the Incident table
var incidentGR = new GlideRecord('incident');
// Apply filters to retrieve incidents within the specified time frame
incidentGR.addQuery('sys_created_on', '>=', startDate);
incidentGR.addQuery('sys_created_on', '<=', endDate);
// Group incidents by their identifying field (e.g., short description)
incidentGR.groupBy('short_description');
// Count the number of identical incidents
incidentGR.addAggregate('COUNT', 'short_description', 'identical_incidents');
// Execute the query
incidentGR.query();
// Loop through the result set and print the number of identical incidents for each short description
while (incidentGR.next()) {
var shortDescription = incidentGR.getValue('short_description');
var identicalIncidents = incidentGR.getValue('identical_incidents');
gs.info('Number of identical incidents for short description "' + shortDescription + '": ' + identicalIncidents);
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi