request item stuck in stage waiting for approval

mregragui_ext
Tera Contributor

Hello community,

i have some RITM that is stuck in the stage waiting for approval how can i autoclose ritm stuck in this stage for 3 days.

this is the solution i am trying to implement but it's not working

Capture d’écran 2023-09-06 111410.pngCapture d’écran 2023-09-06 111432.png

in the advanced section i have added this script 

(function executeRule(current, previous /*null when async*/) {
 
// Add your code here
    // Define the 'waitingForApproval' stage value you want to target
    var targetStage = 'waiting_for_approval';
    
    // Get the current stage of the request item
    var currentStage = current.stage;
 
    // Check if the request item is in the target stage
    if (currentStage == targetStage) {
        // Get the requested date
        var requestedDate = current.requested_date;
 
        // Calculate the time difference in milliseconds
        var currentTime = new GlideDateTime();
        var timeDifference = currentTime.getNumericValue() - requestedDate.getNumericValue();
        
        // Calculate the time difference in days
        var timeDifferenceDays = timeDifference / (1000 * 60 * 60 * 24);
 
        // Define the threshold (in days) for auto-closure (e.g., 3 days)
        var autoCloseThreshold = 3;
 
        // Check if the request item has been in the target stage for more than the threshold
        if (timeDifferenceDays >= autoCloseThreshold) {
            // Set the request item to closed (you can customize this part)
            current.active = false;
current.state = 7;
            current.closed_at = new GlideDateTime();
            current.close_code = 'Closed by Business Rule';
            current.close_notes = 'Auto-closed after ' + autoCloseThreshold + ' days in ' + targetStage;
            
            // Update the request item
            current.update();
        }
    }
 
})(current, previous);
0 REPLIES 0