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

Hi @Harsha34 ,

 

Try the below:

 

autoCloseRITM();

function autoCloseRITM() {

    var gr = new GlideRecord('sc_req_item');
    gr.addQuery('sys_id', 'eb3ed899c38302103869d64d05013144'); /// 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.query();
    while (gr.next()) {

        var apprRec = new GlideRecord('sysapproval_approver');
        apprRec.addQuery('sysapproval', 'eb3ed899c38302103869d64d05013144'); //RITM sysID
        apprRec.query();
        while (apprRec.next()) {
            if (apprRec.state != 'approved') {
                apprRec.setValue('state', 'rejected');
                apprRec.update();
            }
        }
    }
}

 

 

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

Hi,

If I want to run this for dynamic RITM and not for a particular one then this should be like below

 

apprRec.addQuery('sysapproval',current.sys_id);

 

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.

Hi,

Thanks a lot :). It worked perfectly.

Hope I will always get your help!!

Thanks, Happy to assist.

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