VMware Cloud Community
VMSE
VMware Employee
VMware Employee
Jump to solution

Newbie Question - Please Help

Hi I am trying to create a simple workflow where I create a DataCentre Object and then Create a Cluster under the DataCentre Object. The problem is I cannot find a way to take the subsequent DataCentre object from the CreateDataCentre workflow and find the HostFolder so I can then pass that as the attribute to the input of the CreateCluster workflow. I cannot find an action that will do this for me and I haven't been able to successfully write the script to to this. It seemed to me that the HostFolder was an attribute of the DataCentre object and I could reference by stating something like myhostfolder = mydatacenter.hostfolder - it has been years since I have done any scripting and when I did it was vbscript - I am obviously having some difficulty with the object model and I cannot find any sample code that would allow me to understand it a bit better.

Would really appreciate some guidance on how to do this.

Thanks

Michael

0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

🙂

This is something I had to learn more than one time... the given value is an array as the error shows.

So it has to look like:

var myDCs = VcPlugin.getAllDatacenters();

for(i in myDCs){
     if(myDCs[i].name == "newDatacenter1"){
          System.log("hostFolder: "+myDCs[i].hostFolder);
          //if workflow use next line
          hostFolderAttr = myDCs[i].hostFolder;
          //if action uncomment next line
          //return myDCs[i].hostfolder;
     }
}

This returns the hostFolder object. The best way is to build an action returning the value.

best regards

Christian

View solution in original post

0 Kudos
3 Replies
admin
Immortal
Immortal
Jump to solution

Hi Michael,

when you create a new datacenter you will name it like "Datacenter01". After creation you can get the new datacenter with the VcPlugin.getAllDatacenters() method and search the new Datacenter with it´s name. At this point you get the .hostFolder parameter of the new datacenter. This allows you to create the new cluster in the right datacenter Smiley Happy

best regards

Christian

0 Kudos
VMSE
VMware Employee
VMware Employee
Jump to solution

Hi Christian,

Thanks very much for the assistance - but you'll need to be patient while I am getting this. This is what I have in my script action:

var myDC
myDC = VcPlugin.getAllDatacenters(newDatacenter1)
hostfolderattrib = myDC.hostfolder

When I run the workflow I get the error below

Cannot convert Datacenter<datacenter-34>'TESTDC4' to java.lang.String[] (Workflow:TechAcademy /  Get HostFolder (item5)#1)

hostfiolderattrib is of type VC:HostFolder

Is the issue because my var myDC has not be defined as an object -

Thanks

0 Kudos
admin
Immortal
Immortal
Jump to solution

🙂

This is something I had to learn more than one time... the given value is an array as the error shows.

So it has to look like:

var myDCs = VcPlugin.getAllDatacenters();

for(i in myDCs){
     if(myDCs[i].name == "newDatacenter1"){
          System.log("hostFolder: "+myDCs[i].hostFolder);
          //if workflow use next line
          hostFolderAttr = myDCs[i].hostFolder;
          //if action uncomment next line
          //return myDCs[i].hostfolder;
     }
}

This returns the hostFolder object. The best way is to build an action returning the value.

best regards

Christian

0 Kudos