14-Day Automatic Closure of case record with automatic email is triggered to the "requester"

vinnus
Tera Contributor

we have record producer  "Platform Access Request" and respective flow for the case record life cycle.

based on the Request Type choices below

vinnus_0-1746020610285.png

flow will triggers approvals in only 2 choices( first and 4) selection for the record producer.

Now we need to implement 

GIVEN the "Platform access request" case remains unapproved or unrejected by the 14th day
WHEN no action has been taken
AND the case is not assigned to any user
THEN the case is marked as "Closed Incomplete"
AND the case state is updated to "Closed Incomplete" with the "Close code" as "Closed: Not approved"
AND the "Close notes" are updated to: "The case has been closed because it was not approved in the defined time. If you still require the requested action, please submit a new case."
AND an automatic email is triggered to the "requester" and "requested for"

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@vinnus 

you can use flow for this with wait for condition and after 14 days close it and send email

what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

yesterday

vinnus_0-1746253486064.png

 

 

vinnus_1-1746253486068.png

 

for above flow 1 Screenshot If approved(approved) and 2 Screenshot else if if not approved with 4 of other approval states(rejected, skipped,cancelled and no longer required) on top of we need to close the case on 14 day of case opened, when  case state is awaiting approval with approval requested, as per our present flow cases are staying still with awaiting approval we need ensure that 14 days are time out case to get closed with automatic email notification. 

I have tried else if (requested) with timer and wait for condition's nothing works out it.

below is the ask for approval condition's

vinnus_2-1746253486073.png

 

 

 Please suggest how we can achieve my requirement. Thanks

vinnus
Tera Contributor

// Auto-close Financial Cases in 'Awaiting Approval' for 14+ days
var caseGR = new GlideRecord('x_jj_dfit_case');
caseGR.addQuery('state', '5'); // Confirmed: '5' = Awaiting Approval
caseGR.addQuery('record_producer', '58d2d15adbc4341056b9475f29961970');
caseGR.addQuery('opened_at', '<=', gs.daysAgoStart(14));

gs.info('[Auto-Close] Starting query...');
caseGR.query();

var count = 0;

while (caseGR.next()) {
gs.info('[Auto-Close] Found case: ' + caseGR.number + ' | Opened at: ' + caseGR.opened_at);

// Final sanity check inside loop
if (caseGR.state == '5') {
caseGR.state = '4'; // Closed
caseGR.resolution_type = 'Closed: Not approved';
caseGR.close_notes = 'The case has been closed because it was not approved in the defined time. If you still require the requested action, please submit a new case.';
caseGR.closed_at = new GlideDateTime(); // Optional
caseGR.update();
gs.info('[Auto-Close] Case closed: ' + caseGR.number);
count++;
} else {
gs.info('[Auto-Close] Skipped case ' + caseGR.number + ' due to unexpected state: ' + caseGR.state);
}
}

gs.info('[Auto-Close] Total cases closed: ' + count);

Scheduled Jobs > Scheduled Script Executions: i tried below Scheduled Job not working out can please guide
 
 
javascriptCopyEdit(function executeRule(current, gsr) {
    var caseGR = new GlideRecord('x_jj_dfit_case');
    caseGR.addQuery('state', 'awaiting_approval');
    caseGR.addQuery('sys_updated_on', '<=', gs.daysAgoStart(14));
    caseGR.addQuery('producer', '!=', '');
    caseGR.addQuery('item.name', 'Service Management Platform Access Request');
    caseGR.query();

 

    var casesProcessed = 0;

 

    while (caseGR.next()) {
        caseGR.state = '5';
        caseGR.resolution_type = 'Closed: Not approved';
        caseGR.close_notes = 'The case has been closed because it was not approved in the defined time. If you still require the requested action, please submit a new case';
        caseGR.auto_closed = true;
        caseGR.update();
       // gs.eventQueue('fsm.case.auto.closed', caseGR, caseGR.requested_for.email, '');
        casesProcessed++;
    }

 

    gs.info('Auto-closure job processed ' + casesProcessed + ' FSM cases.');
})();