Samstag, 15. Juni 2013

vCenter Orchestrator Code Snippet: get Workflow ID

Hi,
with this code snippet you can easily get the workflow token ID of the currently running workflow:

heres the script, I will explain it afterwards:
var wfToken = null;
try{
var wfTokenURL = workflow.getAnswerUrl().url;
var strwfTokenId1 =  wfTokenURL.substring(wfTokenURL.search("&workflowTokenId=")+17,50000);
var strwfTokenId2 = strwfTokenId1.substring(0,strwfTokenId1.search("&"))
}
catch(objErrMsg)
{
System.error(objErrMsg);
}

Ok, here's the explanation:
"workflow.getAnswerUrl().url" will return something like that:

http://vcoserver:8280/vmo/weboperator/webform.html?cmd=answer&workflowTokenId=8a8989123ed1b4b3013f4992cd5b1e99&returnUrl=http%3A%2F%2F192.168.4.12%3A8280%2Fvmo%2Fweboperator%2Fdefault.html

The yellow part is our ID.

Important is the part before and after our ID, first I split the string in two parts and take the part after &workflowTokenId=(this are the 17 positions I add) to the end.
second thing is taking this part and split it again where the "&" is and get the first part. what you finally got is your ID.

Keine Kommentare:

Kommentar veröffentlichen