palmen
Tera Guru

I've almost got it working now but have some issues with the cancelation of the workflow.


This is my current code



function cancel(){


  if(confirm('Are you sure you want to cancel the New Supplier process?')){


  //Call the UI Action and skip the 'onclick' function


  gsftSubmit(null, g_form.getFormElement(), 'cancel_new_supplier'); //MUST call the 'Action name' set in this UI Action


  return true;   //Abort submission


  }


  return false;


}



// Server side code


if(typeof window == 'undefined')


  cancelNewSupplier();




function cancelNewSupplier(){


  current.active=false;


  current.state=-7;   //Review


  current.close_notes='Flödet för Ny Leverantör har avbrutits av SCM, alla icke utförda arbetsorder har automatiskt stängts';


  new Workflow().cancel(current);



  //Close all active supplier tasks.


  var gr = new GlideRecord('u_supplier_task');


  gr.addQuery('parent', current.sys_id);


  gr.addEncodedQuery('state!=3^state!=4'); //NOT Closed Complete or Closed Incomplete


  gr.addQuery();


  gr.query();


  while (gr.next()){


  gr.state = 4; //Closed Incomplete


  gr.close_notes='Arbetsorder har automatiskt stängts när SCM avbrutit flödet för Ny Leverantör';


  gr.update();


  }



  action.setRedirectURL(current);


  current.update();


  gs.addInfoMessage('The New Supplier Process has been canceled.');


}



The problem is row 19, when the workflow is canceled before I query all the supplier tasks.


The state is set correctly to Close Incomplete, but the close note will be blank for some reason (row 28 and 29). I still want the close notes to be set for all active supplier tasks.



If I cancel the workflow after I query all the tasks (insert row 19 to row 32), the workflow will keep on running and creating the remaining supplier tasks in the workflow that hadn't been created yet. This is not a behaviour I want.



I just want all active supplier tasks to be closed and no new supplier tasks should be created in the workflow and the close note should be set.


How can I do this?


Pradeep Sharma