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
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.
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.
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.
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;
You can get the workflowToken just with using the keyword "workflow" in a scriptable box. That will simplify your script a lot.
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
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.
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