Requested items still show state as open even though the task associated with the request has been closed/complete.

Steve Loritz
Giga Expert

I have about 100 requests that will not change state to closed. These are for catalog items that have been approved, the tasks have been done and marked closed complete. The requests still show as open in My Requests.

Of interest is that the RITM for the REQ stage shows the Completed stage as skipped. (see attachment)

Not sure what is going on. Is there a way I can process the affected items to show the state as closed in My Requests? state still open.JPG

stage skipped.JPG

7 REPLIES 7

Ziaur Rahman1
Tera Expert

Hi, Steve



I think, Issue is with end activity, could you please checkout your workflow and then   open "End" activity , set the stage as "completed" after that publish your workflow, It will resolve the issue.



Thanks


Ziaur Rahman



sending you script to close RITMs


Hello Zia,

 

Am facing the same issue can you help me with this.?

 

Ziaur Rahman1
Tera Expert

Hi Steve,



  • checkClosed();  

 


 


function checkClosed(){  


  var ritm = new
GlideRecord('sc_req_item');  



ritm.addEncodedQuery('active=true^state=1^ORstate=-5^ORstate=2^cat_item=b443af7f4f50c60005214b8e0210c771');


  ritm.query();  


  while (ritm.next()) {  


  var task =
checkTask(ritm.sys_id);  


  gs.addInfoMessage(task);  


  var approvals =
checkApprovals(ritm.sys_id);  


  gs.addInfoMessage(approvals);  


  if (task == 'true' &&
approvals == 'true' ) {  


  ritm.setValue('state',3)  


  ritm.setValue('stage', 'completed');


  ritm.setWorkflow(false);  


  ritm.active = false;  


  ritm.update();  


  closeRequest(ritm.request);  


  }  


 


  }  


}  


function checkTask(ritmSysid)  


{  


  var tsk = 'true';  


  var task = new
GlideRecord('sc_task');  


  task.addEncodedQuery('state=1^ORstate=2^ORstate=-5^ORstate=10^ORstate=11^request_item='+ritmSysid);


  task.query();  


  if (task.hasNext()) {  


  tsk = false;  


  }  


  return tsk;  


}  


function checkApprovals(ritmSysid)  


{  


  var appr = 'true';  


  var app = new
GlideRecord('sysapproval_approver');  


  app.addQuery('state',
'requested');  



app.addQuery('sysapproval',ritmSysid);  


  app.query();  


  if (app.hasNext()) {  


  appr = false;  


  }  


  return appr;  


}  


function closeRequest(requestSysid)  


{  


  var req = new
GlideRecord('sc_request');  



req.addQuery('sys_id',requestSysid);  


  req.query();  


  while(req.next())  


  {  


  req.setValue('request_state',
'closed_complete');  


  req.setWorkflow(false);  


  req.update();  


  }  


}



Please change the state value and sys id according to your environment.



And as this script is to close all ritm and req in one go, so it is quite risky task, I would suggest please test in dev instance first then apply in prod.



Thanks


Ziaur Rahman



Please Mark Correct if your problem get resolved, Sorry for late reply I was on leave so could not get in community.