- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 11:57 PM
Create a Scheduled job to close all the resolved incidents of last month which runs every
month on 3rd at 6am.can anyone explain be briefly about it
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 12:28 AM
Hi @lalithkumar
I think you are new and need step-by-step instructions.
Here you go.
Navigate to schedule jobs system definition>>create new.
Enter the details as follows:
Here is the script:
// Get the first and last days of the previous month
var now = new GlideDateTime();
now.addMonthsUTC(-1); // Move to the previous month
now.setDayOfMonthUTC(1); // Set to the first day
var startOfMonth = now.getValue();
now.addMonthsUTC(1);
now.setDayOfMonthUTC(1); // Set to the first day of the current month
now.addSecondsUTC(-1); // Set to the last day of the previous month
var endOfMonth = now.getValue();
// Query incidents resolved in the previous month
var gr = new GlideRecord('incident');
gr.addQuery('resolved_at', '>=', startOfMonth);
gr.addQuery('resolved_at', '<=', endOfMonth);
gr.addQuery('state', '6'); // Resolved state
gr.query();
// Close each incident
while (gr.next()) {
gr.state = '7'; // Closed state
gr.close_code = 'Closed/Resolved by automation';
gr.close_notes = 'Automatically closed by Scheduled Job on 3rd of the month.';
gr.update();
}
gs.print('Scheduled Job: Closed all resolved incidents of last month.');
***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
***********************************************************************************************************************
Regards
Shaqeel
***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
***********************************************************************************************************************
Regards
Shaqeel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 12:28 AM
Hi @lalithkumar
I think you are new and need step-by-step instructions.
Here you go.
Navigate to schedule jobs system definition>>create new.
Enter the details as follows:
Here is the script:
// Get the first and last days of the previous month
var now = new GlideDateTime();
now.addMonthsUTC(-1); // Move to the previous month
now.setDayOfMonthUTC(1); // Set to the first day
var startOfMonth = now.getValue();
now.addMonthsUTC(1);
now.setDayOfMonthUTC(1); // Set to the first day of the current month
now.addSecondsUTC(-1); // Set to the last day of the previous month
var endOfMonth = now.getValue();
// Query incidents resolved in the previous month
var gr = new GlideRecord('incident');
gr.addQuery('resolved_at', '>=', startOfMonth);
gr.addQuery('resolved_at', '<=', endOfMonth);
gr.addQuery('state', '6'); // Resolved state
gr.query();
// Close each incident
while (gr.next()) {
gr.state = '7'; // Closed state
gr.close_code = 'Closed/Resolved by automation';
gr.close_notes = 'Automatically closed by Scheduled Job on 3rd of the month.';
gr.update();
}
gs.print('Scheduled Job: Closed all resolved incidents of last month.');
***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
***********************************************************************************************************************
Regards
Shaqeel
***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.
***********************************************************************************************************************
Regards
Shaqeel