How to modify business rules so they update the RITM and request states on rejection

Rob C
Kilo Contributor

I'm looking for some help as I'm not a scripter.

We have request workflows that when rejected by the approver  they close the RITM and request with State/Request State Closed Complete. We'd like them to change state to Closed Rejected (a new choice we created) of Closed Incomplete which is present out of the box.

I've checked the business rules as these override using a set values activity I added to the workflows to change states. There are several business rules which look like they might be involved one is Close Parent if Required.

Looking at the script it looks as though the only setting applied to request stage is Closed Complete:

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();
     }
  } 
}

There is also another BR called Mark Request Closed:

if (current.request_state == "closed_complete" ||
 current.request_state == "closed_incomplete" ||
 current.request_state == 'closed_cancelled' ||
 current.request_state == 'closed_rejected' ||
 current.stage == "closed_complete" ||
 current.stage == "closed_incomplete") {
 
 current.active = false;
 
 if (current.closed_by.nil())
  current.closed_by = gs.getUserID();
 
 if (current.closed_at.nil())  {
  current.closed_at = gs.nowDateTime();
  current.business_duration = gs.calDateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),false);
  current.calendar_stc = gs.dateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),true);
 }
 
 if(current.state == 1) {
  var state = current.request_state.indexOf('closed') == 0 ? current.request_state : current.stage;
  switch(state + '') {
   case 'closed_complete':
   current.state = 3;
   break;
   default:
   current.state = 4;
   break;
  }
 }
 
}

So what I'm looking for help on is how to ensure that when an approver has rejected a request/RITM that this is reflected in the state/request state of both the Request and RITM.

8 REPLIES 8

Michael Fry1
Kilo Patron

In your workflow, after the Rejection approval, just use a Set Value activity and set the State to Closed Rejected and Active is false.

I tried that first but I wonder if the values don't change because a rejection results in closure of the RITM and REQ automatically, which is how I ended up chasing the relevant business rules that are managing this.

 

Can you post your workflow so I can see how you have it setup after the approval rejection?

Rob C
Kilo Contributor

Here is the workflow. There is a step which skips the approval is the request is made by the line manager. Then comes the Approval User step. I can see that the Approval action changes the state of the RITM to closed complete and I believe that this triggers task, RITM and request closures and making them inactive. Set Values then doesn't change anything.

find_real_file.png