scheduled job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2024 10:39 PM
can you write a scheduled job script to check if there are 5 incident created in a day with the 'hardware' category, then you need to create a problem ticket and assign it to the manager of the hardware group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2024 10:54 PM
You can create a schedule job to run in the mid night daily at 11:50 with below script
function checkIncidentsAndCreateProblem() {
// Set the date range for today
var now = new GlideDateTime();
var startOfDay = new GlideDateTime();
startOfDay.setDisplayValue(now.getDate().getLocalDate().toString() + " 00:00:00");
// Query for incidents created today with category 'hardware'
var incidentGr = new GlideRecord('incident');
incidentGr.addQuery('category', 'hardware');
incidentGr.addQuery('sys_created_on', '>=', startOfDay);
incidentGr.query();
// Check if there are at least 5 incidents
if (incidentGr.getRowCount() >= 5) {
// Create a new problem ticket
var problemGr = new GlideRecord('problem');
problemGr.initialize();
problemGr.short_description = 'Hardware incidents exceed threshold';
problemGr.assignment_group = hardwareGroupMgr; //sys_id of hardware group
problemGr.insert();
}
}
checkIncidentsAndCreateProblem();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2024 10:54 PM
Did you tried anything? If so, please share what you tried and where you stuck.
Happy to help:)
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2024 11:00 PM
Hi Kongaleti,
The below code should work for you.
var inc = new GlideRecord('incident');
inc.addEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^category=hardware');
inc.query();
var count = inc.getRowCount();
if(count >= 5){
var prb = new GlideRecord('problem');
prb.initialize();
prb.short_description = 'Hardware category more than 5 incidents';
prb.category = 'hardware';
prb.insert();
}
If my answer helped you in anyway please mark it as correct.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2024 11:15 PM
Hi @Kongaleti Navee why dont you use flow designer with trigger as scheduled and have a look up on incident record , no code required
Harish