How to Cancel the workflow execution through UI Action

Suzy
Tera Contributor

Hi All,

I have written the below code but nothing is working. Please suggest.

Please note that the UI Action is on my custom table.

function withdraw(){
     if(confirm('Are you sure you want to cancel this request?')){
         //Call the UI Action and skip the 'onclick' function
         gsftSubmit(null, g_form.getFormElement(), 'loaner_res_withdraw'); //MUST call the 'Action name' set in this UI Action
         return true;   //Abort submission
     }
     return false;
}
// Server side code


if(typeof window == 'undefined')
     serverLoanerWithdraw();

function serverLoanerWithdraw(){
   current.active=false;
   current.state=5;
	var workflow= new Workflow();
   //workflow.cancel(current); // this doesn't work, if this line is removed the rest of the action works
   action.setRedirectURL(current);
   current.update();

}

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi Suzy,

 

It is possible to implement a UI action to cancel a workflow.

Quick clarification, have you ensured the 'Client' checkbox is set to true and within the 'Onclick' section you are calling withdraw()

Ensuring these attributes are set, tweak your server function script slightly as follows:

 

function serverLoanerWithdraw(){

new Workflow().cancel(current);

current.active=false;

current.state=5;

current.update();

action.setRedirectURL(current);

}

 

To help others, please mark as correct and/or helpful.

Thanks,

Robbie

View solution in original post

7 REPLIES 7

Robbie
Kilo Patron
Kilo Patron

Hi Suzy,

 

It is possible to implement a UI action to cancel a workflow.

Quick clarification, have you ensured the 'Client' checkbox is set to true and within the 'Onclick' section you are calling withdraw()

Ensuring these attributes are set, tweak your server function script slightly as follows:

 

function serverLoanerWithdraw(){

new Workflow().cancel(current);

current.active=false;

current.state=5;

current.update();

action.setRedirectURL(current);

}

 

To help others, please mark as correct and/or helpful.

Thanks,

Robbie

Suzy
Tera Contributor

Hi Robbie,

Thanks for your reply, it's working as expected.

 

No worries. Glad it worked. Thanks for letting me know and also marking my response correct. This will help others with the same question.

Thanks,

Robbie

Suzy
Tera Contributor

Hi Robbie,

 

Thanks for that, i have small issue here. Everything is working but the state is not updated correctly.

Please suggest

Thank you.