Hello,
I am trying to do some error handling in my vCO workflows, so I found the Exception tab on the workflow element. However I am looking for an alternative to avoid modifying the workflow element code to put the try/catch statements. Is there anything like a wrapper for workflow elements, or maybe there is a way to call a workflow element from a scriptable task, so I can put a try/catch around it and handle the exception without touching the code inside the element?
Thank you,
Juan.
You can call a workflow via a script. The scriptable object for a workflow has a .execute() method.
You could just wrap the workflow in another workflow that does nothing but call the workflow. Then just set a success route to a normal finish and an error route to a script or action to handle the error as you see fit.
The way I typically handle error handling (with scriptable tasks) is to run the code and have it output the result to a variable, and then I evaluate the variable for whether or not the an exception needs to be thrown. I don't think there's any way to work around it other than to use a throw... but, I could be wrong.
Yes, I am under the same impression. Although given that I am using the Guest Script Manager package by Christophe: Guest script manager package I would prefer not to mess up with the code and do the error handling at a higher level. Hopefully somebody can shed some light on this matter.
It really depends on what you're trying to do error handling / capturing on.. If we're talking about having the script run then evaluate the content in the output, then that's pretty easy... Set the workflow action to output the script output to a variable, then execute your error handle against that output.. For scripts where there may not be an output (let's say you're starting a service, as an example), what I do is I execute the command to start the service, then I run a second command to get the state of the service.. then I parse the output of the text for the state of it from within the workflow post-script run... That way, you're not digging into the guest script manager core (which I've had to do a bit of, too).
Is that helpful?
Capturing the output is not so much the issue in my workflows, when using the PowerShell plugin I can get that, but sometimes I get exceptions from the commands I run in the guest, like working with cmdlets that do things in AD, etc. Your suggestion is good for the PowerShell plugin but in the case of the Guest script manager package I get exceptions for different reasons and I would like to capture them instead of failing the workflow run. I might have to start digging into the code too...
Thanks for the help.
You can call a workflow via a script. The scriptable object for a workflow has a .execute() method.
You could just wrap the workflow in another workflow that does nothing but call the workflow. Then just set a success route to a normal finish and an error route to a script or action to handle the error as you see fit.
Thanks a lot. That was what I was looking for. I created a workflow that has a workflow object as an input and the input parameters of the other, then I have to create a Properties object and pass them to the execute method:
var props = new Properties();
props.put("vm",vm);
props.put("domain",domain);
props.put("vmUsername",vmUsername);
props.put("vmPassword",vmPassword);
props.put("adGroup",adGroup);
wf.execute(props);
I'm a visual person, so I have to ask.. why would the preferred approach be to run a workflow from a scriptable task vice calling a workflow element from within another workflow?
You can always use A scriptable task on error path of a nested workflow like in attached screenshot. After that you can do what ever you find appropriate.
This works perfectly, thanks. And you can pass the error code to the script task by binding the error to an attribute on the workflow Exception tab.