VMware Cloud Community
mythrandir52
Contributor
Contributor

Get VCAC:VirtualMachine by partial name

I am trying to develop an action i can call as part of one of my workflow that will return a list of vcac:virtualmachines based on a filter i provide so the client get a drop down list to choose from.  The problem i am have is that my code below works find if i provide the whole vm name but doesnt return anything if i use a partial name.  Eventually i will provide another filter to filter by business group as well but i am working up to that.  What am i doing wrong?

The whole server name:

"ap-script-p001"

Test code:

var Pattern = 'ap-script';

var vms = Server.findAllForType("vCAC:VirtualMachine", "substringof(VirtualMachineName, '" + Pattern + "') eq true")

for each (var vCACVirtualMachine in vms) {

  System.log("name:"+vCACVirtualMachine.VirtualMachineName);

}

with the code above nothing comes back

With the whole name it returns the object.  I want to be able to enter a partial name and the client can choose their specific box for a drop down.

Truth is a three edged sword
Tags (1)
Reply
0 Kudos
1 Reply
iiliev
VMware Employee
VMware Employee

Hi,

I think the problem is with the order of parameters when you call substringof(). As far as I know, substringof() checks whether the first parameter is a substring of the second parameter.

So in your case the first parameter in substringof() should be the pattern.

This also explains why your code works if the pattern is equal to the whole machine name (in this case both parameters are equal, and any string is a substring of itself).

Reply
0 Kudos