When REQ is submitted automatically RITM is closing

sriram35
Kilo Guru

Hi,

When I have submitted REQ, RITM is creating, under RITM Tasks generated.

But when REQ is submitted automatically RITM is going to a closed complete state, But all the Tasks are in the open state only. 

When Tasks are closed then only RITM and REQ should be closed. 

 

Please help me

 

Thanks

Sriram

5 REPLIES 5

Swapnil Soni1
Giga Guru

Hi sriram,

You should have a business rule on Requested item table, which can trigger the closure.

Below is an example.

 

closeParentIfRequired();

 

function closeParentIfRequired(){

  // check to see if any of our peers are currently *not* closed

  var gr = new GlideRecord('sc_req_item');

 

  gr.addQuery('request', current.request);

 

  gr.addQuery('stage', '!=', 'complete');

 

  gr.addQuery('stage', '!=', 'Request Cancelled');

 

  gr.query();

 

  if (!gr.next()) {

 

        // no peer task is currently open

 

        var sc_request = new GlideRecord('sc_request');

 

        sc_request.addQuery('sys_id', current.request);

 

        sc_request.query();

 

        sc_request.next();

 

        gs.print("SC_REQUEST.STAGE = " + sc_request.stage + " INDEX = " + sc_request.stage.toString().indexOf('closed'));

 

        if (sc_request.stage.toString().indexOf('closed') == -1) {

 

                sc_request.stage = "closed_complete";

 

                sc_request.comments.setJournalEntry("Request Automatically Closed as all Line Items were complete");

 

                sc_request.update();

 

        }

 

  }  

 

}

 Please mark correct or helpful if this helps.
Thanks
Swapnil