VMware {code} Community
madady
Contributor
Contributor
Jump to solution

Exit workflow

Hello everyone,

Can somebody tell me (or point me in the right direction) on what I would have to do in order to end a workflow's execution from inside the workflow?

I am writing quite large scripting sections in my workflow and I am doing all sorts of validations. I would like to be able to end the workflow from within the scripting section, without the need to set a flag and test for it at the end of the scriptable task. So, I would need something like Java's System.exit(), but I can't seem to find it anywhere in the API. I guess an acceptable solution would be to throw an exception, but that seems messy.

Thanks.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

Hi Adrian,

Do you want to cancel a different workflow from within your custom script or you are trying to cancel the same workflow?

As a general step to cancel a workflow execution, you would need to get the running instance of workflow token for the worklfow, which has a method defined as cancel(). This method would cancel the workflow on whose workflow token you invoke the method. You can get the workflow token for a workflow by taking the same as the input parameter, of type WorkflowToken, selecting the desired running instance to be cancelled and then invoking the cancel method.

You can also call the executeworkflow method to execute a workflow within your script, which returns a workflow token for that workflow, and then you can use the same to cancel the workflow. In the nut shell, you need to get the workflow token and then use cancel method.

I hope this would be helpful for you.

View solution in original post

0 Kudos
2 Replies
admin
Immortal
Immortal
Jump to solution

Hi Adrian,

Do you want to cancel a different workflow from within your custom script or you are trying to cancel the same workflow?

As a general step to cancel a workflow execution, you would need to get the running instance of workflow token for the worklfow, which has a method defined as cancel(). This method would cancel the workflow on whose workflow token you invoke the method. You can get the workflow token for a workflow by taking the same as the input parameter, of type WorkflowToken, selecting the desired running instance to be cancelled and then invoking the cancel method.

You can also call the executeworkflow method to execute a workflow within your script, which returns a workflow token for that workflow, and then you can use the same to cancel the workflow. In the nut shell, you need to get the workflow token and then use cancel method.

I hope this would be helpful for you.

0 Kudos
Andreas_Diemer
Enthusiast
Enthusiast
Jump to solution

Hi madady,

in summary of Angela - to cancel a workflow inside itself (this), just use:

workflow.cancel();

This is like the System.exit() you've mentioned.

The word "workflow" show be colored red in vCO editor (keyword).

This keyword "workflow" represents the running instance (=WorkflowToken object). So you can use all properties and methods from the WorkfloToken object on the "workflow" item (=this).

-


Regards,

don't forget: award points to helpful answers

visit

------ for correct and / or useful answers please award points visit http://www.vcoteam.info & http://mighty-virtualization.blogspot.com