Incident management question adjusting on hold attempt 1,2,3 behaviour

Norton Foskett
Mega Expert

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.

 

 

 

1 ACCEPTED SOLUTION

Norton Foskett
Mega Expert

Resolution was to create 2 things 

1. Workflow creation.

1.png2.png3.png4.png

 

 

2. Sla task Creation

6.png7.png8.png

 

So I was able to fix it myself,

 

Kind regards,

Norton Foskett 

View solution in original post

3 REPLIES 3

Norton Foskett
Mega Expert

Trying to fix it with a scheduled job using the following script

 

var DAYS_LIMIT = 7;
var ATTEMPT_1 = 1;
var ATTEMPT_2 = 2;

 
var gr = new GlideRecord('incident');
gr.addQuery('contact_count', 'IN', ATTEMPT_1 + ',' + ATTEMPT_2);
gr.query();

while (gr.next()) {
    
    var currentDate = new GlideDateTime();
   
    var createdDate = gr.sys_created_on;
   
    var diff = gs.dateDiff(currentDate.getDisplayValue(), createdDate.getDisplayValue(), true);
   
    if (diff <= DAYS_LIMIT) {
        
        gr.state = 'in_progress';
        gr.update(); // Update the record
    }
}
 
gonna keep you guys updated if it works 
 
Kind regards,
Norton Foskett 

Norton Foskett
Mega Expert

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 

 

Norton Foskett
Mega Expert

Resolution was to create 2 things 

1. Workflow creation.

1.png2.png3.png4.png

 

 

2. Sla task Creation

6.png7.png8.png

 

So I was able to fix it myself,

 

Kind regards,

Norton Foskett