RITM should get closed Incomplete and approval state rejected if RITM is not approved since 7 days.

Harsha34
Tera Expert

Hi,

 

My requirement is if RITM is not approved since 7 days then the approval should get rejected and RITM should get closed incomplete. I tried below script for change request on my PDI and it ran except for approval rejected part since approvers were not there. BUT when I am trying this for RITM on my instance it does not run. Please help me out in finding out the mistake.

 

I created this property glide.ui.autoreject.time_req with integer value 7 and a schedule job as below:

 

Harsha34_0-1722321341521.png

After business rule as below:

 

autoCloseRITM();

function autoCloseRITM() {
    var ps = gs.getProperty('glide.ui.autoreject.time_req');
    var pn = parseInt(ps);
    var queryTime = new GlideDateTime();
    queryTime.addDaysUTC(-pn);

    if (pn > 0) {
        var gr = new GlideRecord('sc_req_item');
        gr.addQuery('sys_id', '765f876b87530e50209ded3cbbbb3516'); /// testing this for a single RITM
        gr.addEncodedQuery('approval=requested^sys_created_onONThis month@javascript:gs.beginningOfThisMonth()@javascript:gs.endOfThisMonth()');
        gr.addQuery('sys_updated_on', '<', queryTime);
        gr.query();
        while(gr.next()) {
            gs.addInfoMessage(gr.sys_id+ " sysid is 765f876b87530e50209ded3cbbbb3516 ");

            gr.state= 4;
            gr.active = false;
            gr.update();
        }
    }
}
 
Please suggest.
1 ACCEPTED SOLUTION

In Scheduled job, current won't work.

 

so, you can go ahead with gr.sys_id as this will have the RITM sysID.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

9 REPLIES 9

SN_Learn
Kilo Patron
Kilo Patron

Hi @Harsha34 ,

 

Try the below in scheduled job/background script:

autoCloseRITM();

function autoCloseRITM() {
    //var ps = gs.getProperty('glide.ui.autoreject.time_req');
    //var pn = parseInt(ps);
    //var queryTime = new GlideDateTime();
   // queryTime.addDaysUTC(-pn);

   // if (pn > 0) {
        var gr = new GlideRecord('sc_req_item');
        gr.addQuery('sys_id', '765f876b87530e50209ded3cbbbb3516'); /// testing this for a single RITM
        gr.addEncodedQuery("sys_created_onRELATIVELT@dayofweek@ago@7^approval=requested^active=true"); //This will check for RITM not approved in 7 days from the created date
        //gr.addQuery('sys_updated_on', '<', queryTime);
        gr.query();
        while(gr.next()) {
            gs.addInfoMessage(gr.sys_id+ " sysid is 765f876b87530e50209ded3cbbbb3516 ");
            gr.setValue('state', 4);
            gr.setValue('active', false);
            gr.update();
        }
//    }
}

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Hi,

Thanks a lot for responding to my post. I tried this in background script and the approval got rejected but in the Approvals related list of RITM, the requested state has No Longer Required. Can you please let me know why this is so but in the list view for approval column it is showing as Rejected

 

I have tried for an RITM with approvals in related list as requested.

Harsha34_2-1722325699672.png

Harsha34_3-1722325778922.png

In List view of RITM below:

 

Harsha34_4-1722325848098.png

 

 

Please let me know what to do if I want to set the requested state as Rejected in approvals in related list of RITM and also RITM should get Closed incomplete as it is working now.

 

 

 

Hi @Harsha34 ,

 

This is Out of the box functionality, if a RITM is cancelled then the related approval records(these are stored in [sysapprval_approver] table) are set to 'No longer required' and approval will show as rejected.

 

The below article explains about the business rule responsible to set it: 

Requested item (RITM) gets closed completed after rejecting approval where it should be in fulfillme... 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

I rejected an approval and the RITM went to Closed Incomplete, so Is it possible to change requested state of approval as rejected so that RITM automatically goes to closed incomplete.

The condition would be same : approval is in requested state since 7 days and so we rejected that approval and RITM went to closed Incomplete automatically.

Like below:

Harsha34_0-1722329217828.png

 

Harsha34_1-1722329279479.png