Hello,
I am using the action made by Christophe (http://www.vcoteam.info/learn-vco/code-snippets-cancel-one-of-your-running-workflows.html) in order to abort some workflows.
Since the selection window for the tokens does not display parameters of the token, i created another input for my workflow which is supposed to contain the name of the VM, just for infomational purposes.
I've created an action to do this. When i just use "return myWorkflowToken.getInputParameters();" then all parameters are being written into the input box.
In my case it looks like this:
{ram=3000.0, date=Mon Jan 24 16:25:16 CET 2011, vm=<FinderResult @id='VC:VirtualMachine/si0vm271/vm-852' @name='si0vm562' >, cpu=3.0}
Since i only need the name of the VM, in this case the part after @name (si0vm562), i need to extract it somehow out of the string.
In the Orchestrator API i found the String class with the method "split".
At first i tried to split the string in two parts using this code:
var params_s = myWorkflowToken.getInputParameters();
var params_a_s = params_s.split("name");
return params_a_s[1];
But when i execute the workflow, the input dialogue tells me that the function "split" can not be found.
How can i extract the VM name out of the InputParameters of a running workflow?
Thank you
Regards
Andreas
Hi Andreas,
I don't think splitting strings works for your case.
The workflowToken.getInputParameters() actually does not return string. It is ch.dunes.scripting.jsmodel.JSProperties instead (you can check this from the orchestrator client Tools ->API Explorer). That is why split function can't be found on the params_s variable.
In order to achieve your goal you can try the following:
// get the vm parameter
// use the parameter name. Here is used vm as per your post results
var vm = workflowToken.getInputParameters().get("vm");
// you can check for safety if the vm is set, except the vm is required parameter
if (vm != null) {
return vm.name
}
The above snippet should return you the value set for the vm parameter.
Hope this helps,
Martin Marinov
Is split the right thing to use? It will cut your string into two halfs at "name", as it splits the string at each occurance of "name".
What about searching for the index of "name=' " and " '>" with indexOf and then use substring with these indexes to get the name?
AWo
Hi Andreas,
I don't think splitting strings works for your case.
The workflowToken.getInputParameters() actually does not return string. It is ch.dunes.scripting.jsmodel.JSProperties instead (you can check this from the orchestrator client Tools ->API Explorer). That is why split function can't be found on the params_s variable.
In order to achieve your goal you can try the following:
// get the vm parameter
// use the parameter name. Here is used vm as per your post results
var vm = workflowToken.getInputParameters().get("vm");
// you can check for safety if the vm is set, except the vm is required parameter
if (vm != null) {
return vm.name
}
The above snippet should return you the value set for the vm parameter.
Hope this helps,
Martin Marinov
Hi Martin,
this works like a charm. Many thanks to you.
PS: I'd like to klick on the "correct answer" button, but they seem not to be working. When i click them, they just redirect me to the top of the page.
They worked last week AFAIR.
Hi Andreas,
You are welcome. You can try this later on, since there is no go to answer link.
Regards,
Martin