Mark Request Closed Incomplete via Request Item

Brendan Hallida
Kilo Guru

Hi all,

When our request items are completed (Closed Complete), they, in turn, set the parent request's state and request state to Closed Complete.

The issue that I am having is if a request item was to change to the state Closed Incomplete, the request state and state of the request is still set to Closed Complete.

I have found 2 before business rules that are running in the environment, that I can only assume came from the implementer or are OOB BRs.   They were both created by glide.maint.

Mark Request Closed

Table: Request

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;

  }

  }

}

Set Request State

Table: Request

setDesiredState();

function setDesiredState() {

      var desired = getDesiredState();

      gs.print("DESIRED = " + desired);

      current.request_state = desired;

}

function getDesiredState() {              

      var desired = current.request_state;

      if (desired == 'closed_cancelled') // if we're cancelled we're cancelled

              return desired;

      gs.print("APPROVAL = " + current.approval + " CHANGES = " + current.approval.changes());

      gs.print("CURRENT STAGE = " + current.stage);

     

      if (current.approval.changesTo('approved')) {

              desired = 'in_process';

      } else if (current.approval.changesTo('rejected')) {

              desired = 'closed_rejected';

              current.stage = 'closed_incomplete';

              current.state = 4;

      } else if (current.stage == 'closed_complete')

                desired = 'closed_complete';

      return desired;

}

I would like the request state and state change to Closed Incomplete if the requested item is set to Closed Incomplete.

Cheers,

Brendan

3 REPLIES 3

vinitha3
Tera Guru

Hi,



I have seen that when catalog tasks are closed, the request is closed and no idea on the flow between RITM and REQ.


But I had created a created a BR which updates the REQ to closed when RITM is closed which was needed because that logic did not have a task associated with it.



Thanks,


VInitha.K


anjalichoudhary
Kilo Guru

Hi Brendan,



There is one out of the box business rule named as 'Close Parent if Required', you need to modify its condition as below:



Condition: (current.stage.changes() && (current.stage=='complete' || current.stage=='Request Cancelled') && current.state!='4')   // 4 is Close Incomplete value for RITM Status



And then you have to create another Business Rule on Requested Item table and run it on After Update. Put Filter condition, Status changes to Close Incomplete and in script part apply below code:



function onAfter(current, previous) {


  //This function will be automatically called when this rule is processed.


  var item_status = current.state;


  var rec = new GlideRecord('sc_request');


  if(rec.get(current.request))


  {


  if(item_status == '4'){                                                                     // 4 is Close Incomplete value for RITM Status


  rec.request_state = 'closed_incomplete'; }


  rec.update();


  }


}



Hope it will help you to resolve the issue.



Regards,


Anjali


I can't get this to work for me. Anyone got it working?