How to cancel open approvals via UI Action ?

Zod
Giga Guru

Hi,

I created a workflow (not on any task related table ... ) and it works fine.

After a UI action changes the status field the workflow approval will be set to cancelled

Current script in UI action;

function onClickl(){

  if(confirm('Sure?')){  

  gsftSubmit(null, g_form.getFormElement(), 'action_name');

  }

  return false;

}

// Server side code

if(typeof window == 'undefined')

  abC();

function abC(){

  current.install_status= '123';

  current.update();

  var wf = new Workflow();

  wf.cancel(current);

  new WorkflowApprovalUtils().cancelAll(current, comment);

  new Workflow().restartWorkflow(current);

}

When using the Ui Action, the approval in the workflow are set to cancelled (looks fine) .. nevertheless the approval tasks are still active for the approvers.

Additionally when restart the Workflow with the same conditions - old approvals already given will apply automatically ... .

I assume something is missing that will kill all approval tasks when using the ui action ... somehow I could not find it till now ...

Thank you!!

3 REPLIES 3

vinitha3
Tera Guru

You to have query the approval table and set the status to "No longer approval required". In that way the status is set and approval tasks are cancelled.



Thanks,


VInitha.K


ok sounds logically. How to do? Via a Business Rule that is trigged via the status?


Through run script activity in workflow,



gatherNLR();


       


      function gatherNLR() {


      var ga = new GlideRecord('sysapproval_approver');  


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


      var gr = ga.addQuery('sysapproval.approval', 'requested');


      gr.addOrCondition('sysapproval.approval', 'approved');


      gr.addOrCondition('sysapproval.approval', 'rejected');


      var gr1 = ga.addQuery('sysapproval.state', '3');


      gr1.addOrCondition('sysapproval.state', '6');


      gr1.addOrCondition('sysapproval.state', '7');


      ga.query();


      gs.log('The sys_approval_approver table has ' + ga.getRowCount() + ' rows that needs to be in No longer Requested status...');


      while (ga.next()) {


      ga.setValue('state', 'No Longer Required');


      ga.update();


  }


}



Thanks,


Vinitha.K



PS: Hit answered, like, Helpful or Correct depending on the impact of the response.