- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 04:44 AM
Small question, at the moment in our incident management module we have configured that tickets close after 7 days automatic when in attempt 3, but I also need to have that when in attempt 1 or 2 after 7 days ticket goes to in progress automatic.
Is this easy configurable? have been looking into business rules but do not see how to achieve this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 01:36 AM
Resolution was to create 2 things
1. Workflow creation.
2. Sla task Creation
So I was able to fix it myself,
Kind regards,
Norton Foskett
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 01:47 AM
Trying to fix it with a scheduled job using the following script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 05:47 AM
Noticed that some some fields in database are different then in script adjusted it, testing it now.
Results will be posted some time later.
var DAYS_LIMIT = 7; // Define the number of days limit
var ATTEMPT_1 = 'attempt 1';
var ATTEMPT_2 = 'attempt 2';
var ON_HOLD_STATE = 3; // The state number for 'On Hold'
var IN_PROGRESS_STATE = 2; // The state number for 'In Progress'
// Get the current date and time
var now = new GlideDateTime();
// Query the state transitions related to 'On Hold' state and 'attempt 1' or 'attempt 2'
var gr = new GlideRecord('sys_history_line');
gr.addQuery('set', 'incident');
gr.addQuery('field', 'incident_state');
gr.addQuery('new_string', 'On Hold');
gr.addQuery('old_string', '!=', 'On Hold'); // Ensure the previous state is not 'On Hold'
gr.addQuery('created', '>=', now); // Only consider state transitions created before the current date
gr.orderByDesc('sys_created_on');
gr.query();
gs.log("Starting the script to check contact count and update state", "Test Script");
while (gr.next()) {
var sysId = gr.documentkey.toString();
gs.log("Processing record: " + sysId, "Test Script");
// Get the current date of the state transition
var stateChangeDate = new GlideDateTime(gr.sys_created_on);
// Get the time of the state transition
var stateChangeTime = stateChangeDate.getNumericValue() / 1000; // Convert milliseconds to seconds
// Query the incident record
var incident = new GlideRecord('incident');
if (incident.get(sysId)) {
// Get the current state of the incident
var currentState = incident.getValue('incident_state');
// Query the previous state of the incident
var prevState = new GlideRecord('sys_history_line');
prevState.addQuery('documentkey', sysId);
prevState.addQuery('field', 'incident_state');
prevState.addQuery('created', '<', gr.sys_created_on); // Consider only state transitions before the current one
prevState.orderByDesc('sys_created_on');
prevState.setLimit(1); // Get the latest state transition before the current one
prevState.query();
if (prevState.next()) {
var previousState = prevState.new_string.toString();
// Check if the previous state is 'On Hold' and the current state is 'In Progress'
if ((previousState == ON_HOLD_STATE) && (currentState != ON_HOLD_STATE)) {
// Calculate the time spent in 'On Hold' state
var timeInOnHold = stateChangeTime - (new GlideDateTime(prevState.sys_created_on).getNumericValue() / 1000);
// Check if the time spent in 'On Hold' state exceeds the limit
if (timeInOnHold >= (DAYS_LIMIT * 24 * 60 * 60)) { // Convert days to seconds
// Set the state to 'In Progress'
incident.setValue('incident_state', IN_PROGRESS_STATE);
incident.update();
gs.log("Record updated to 'In Progress': " + sysId, "Test Script");
} else {
gs.log("Record not updated. Time in 'On Hold' state is within the limit", "Test Script");
}
}
}
}
}
gs.log("Script execution completed", "Test Script");
Kind regards,
Norton Foskett
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 01:36 AM
Resolution was to create 2 things
1. Workflow creation.
2. Sla task Creation
So I was able to fix it myself,
Kind regards,
Norton Foskett