VMware {code} Community
RainerVM
Enthusiast
Enthusiast

How can I get the WorkflowToken of the current running Workflow?

Hi Community,

how can I get the workflow token of the current running workflow?

I know that it is possible to get the workflow token when I start the workflow with the execute method, but what about within an already running workflow?

Best regards,

Rainer

8 Replies
admin
Immortal
Immortal

Hi Rainer,

I am not sure if this is what you looking for, but you can try something with the user interaction, while the workflow is running. In the user interaction, you can take WorkFlowToken as the input parameter which would then populate the list of worklfow tokens present in the server system.

0 Kudos
RainerVM
Enthusiast
Enthusiast

Hi Angela,

thank you for your fast reply, but no that's not what I'm looking for, to get the workflow execution list (WorkflowTokens) is no problem (using a Action or the 'User interaction' all possible).

My problem is to know which single token of these listed tokens is the token of the current running workflow.

0 Kudos
admin
Immortal
Immortal

Lets see if this helps ...

There is a property "endDate" for every Workflow token, which shows the date when this particular workflow token was finished executing. You could retrieve the current token of the workflow by sorting out all the tokens for that workflow in descending order of endDate, the first one being the current token.

Hope this is what you are looking for and it helps.

0 Kudos
RainerVM
Enthusiast
Enthusiast

Hi Angela,

sorry this works also not, because during the execution of the workflow there is no endDate available. And doing the same with the startDate doesn't work either, because it could be that another workflow has been started a view milliseconds later than the current, then I would get the other one and not the current running.

But I found a way to get the current workflow token by myself, a bit tricky but it works

For everyone who is interested in - here you will find the code of an Action (I called it getCurrentWfToken):

Input: none (but must be used within a workflow)

Output: WorkflowToken of the current running workflow

var objWfToken = null;

try {

var strAnswerUrl = workflow.getAnswerUrl().url;

var strWfTokenId = strAnswerUrl .replace(/^(\[\s\S]TokenId=)|(&returnUrl\[\s\S])$/g,"");

objWfToken = Server.findForType("WorkflowToken",strWfTokenId);

} catch (objErrMsg) {

System.error(objErrMsg);

}

return objWfToken;

0 Kudos
cdecanini_
VMware Employee
VMware Employee

You can get the workflowToken just with using the keyword "workflow" in a scriptable box. That will simplify your script a lot.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
mcssschaefer
Enthusiast
Enthusiast

Just for interest: What is "worklfow"? Is it an object? Is there a way to display all builtin "keywords"? I don't found it on the "VCO Developers Guide".

Edit: Ok, it is an object of type WorkflowToken -> WorkflowToken:ch.dunes.scripting.jsmodel.JSWorkflowToken@83bc732.

Is there a list of the objects available in the scripting environment? Any documents?

Thanks in advance,

Sephan

http://blog.mightycare.de http://www.mightycare.de
ashley186
Contributor
Contributor

Thanks for pointing this out, I was trying to do that same thing as the original poster and looking through the scripting API I could not see this documented anywhere (the doco is pretty garbage).

Much Appreciate. Very thanks.

0 Kudos
AliH201110141
Contributor
Contributor

Use the workflow object. I know it's misleading because the object name is "workflow" not "workflowToken" but I tested it. For example, if you want to log the ID and start date of the current running workflow, put the following code in a scriptable task inside the main workflow:

System.log("Token ID: " + workflow.id);

System.log("Token Start Date: " + workflow.startDate);

System.log("Parent workflow name: " + workflow.currentWorkflow.name);

Hope this helps

Ali