The CreatorCon Call for Content is officially open! Get started here.

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

Hi @vinnus 

 

Script seems to be ok. There can be an issue with filter, can you let us know what's not working in script? Are you not getting any records in gliderecord object?

 

I suggest you to add some logs to debug it further.

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

vinnus
Tera Contributor
   //This scheduled job triggers everyday to filter out all the pending approval for 10 days and close them on 14 day Finanicial Case request.
var apprRec= new GlideRecord('sysapproval_approver');
apprRec.addQuery('state','requested');
apprRec.addQuery('sysapproval.sys_class_name','x_jj_dfit_case');
apprRec.addEncodedQuery('record_producer=58d2d15adbc4341056b9475f29961970^state=5^opened_atRELATIVELT@dayofweek@ago@10');
apprRec.query();
while(apprRec.next()){
    gs.eventQueue('x_jj_dfit.approval.reminder',apprRec, apprRec.approver, apprRec.approver.user_name);
}
 
    var caseGR = new GlideRecord('x_jj_dfit_case');
    caseGR.addQuery('state', '5');
    caseGR.addEncodedQuery('record_producer=58d2d15adbc4341056b9475f29961970^state=5^opened_atRELATIVELT@dayofweek@ago@14')
    caseGR.query();
   

    while (caseGR.next()) {
        caseGR.state = '4';
        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.update();
    }

vinnus
Tera Contributor
   //This scheduled job triggers everyday to filter out all the pending approval for 10 days and close them on 14 day Finanicial Case request.

var apprRec= new GlideRecord('sysapproval_approver');
apprRec.addQuery('state','requested');
apprRec.addQuery('sysapproval.sys_class_name','x_jj_dfit_case');
apprRec.addEncodedQuery('^state!=not_required^ORstate=NULL^sys_updated_onRELATIVELT@dayofweek@ago@10');
apprRec.query();
while(apprRec.next()){
    gs.eventQueue('x_jj_dfit.smpaccess.approval.reminder',apprRec, apprRec.approver, apprRec.approver.user_name);
   
}
 
    var caseGR = new GlideRecord('x_jj_dfit_case');
    caseGR.addQuery('state', '5');
    caseGR.addEncodedQuery('record_producer=58d2d15adbc4341056b9475f29961970^state=5^sys_updated_onRELATIVEGT@dayofweek@ago@14');
    caseGR.query();
   
    while (caseGR.next()) {
    caseGR.state = '4';
    //gs.info('state ');
    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.root_cause = 'Security Config';
    caseGR.root_cause_reason = 'Rejected';
    caseGR.update();
    }

vinnus
Tera Contributor

vinnus_0-1746105155059.png

 

vinnus_1-1746105214757.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-1746105774937.png

 

 Please suggest how we can achieve my requirement. Thanks