VMware Cloud Community
Aramaki
Contributor
Contributor
Jump to solution

How to split strings?

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

Reply
0 Kudos
1 Solution

Accepted Solutions
mmarinov
VMware Employee
VMware Employee
Jump to solution

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

Martin Marinov VMware Software Engineer If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points

View solution in original post

Reply
0 Kudos
4 Replies
AWo
Immortal
Immortal
Jump to solution

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

vExpert 2009/10/11 [:o]===[o:] [: ]o=o[ :] = Save forests! rent firewood! =
Reply
0 Kudos
mmarinov
VMware Employee
VMware Employee
Jump to solution

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

Martin Marinov VMware Software Engineer If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points
Reply
0 Kudos
Aramaki
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
mmarinov
VMware Employee
VMware Employee
Jump to solution

Hi Andreas,

You are welcome. You can try this later on, since there is no go to answer link.

Regards,

Martin

Martin Marinov VMware Software Engineer If you found this or any other answer useful please consider the use of the Helpful or correct buttons to award points
Reply
0 Kudos