Hello Community,
I have a asynchronous workflow to clone a couple of VMs and collect the workflow tokens to use ("com.vmware.library.workflow").waitAllWorkflowComplete(arrayOfWorkflowtoken).
I struggle with the returned actionResult Array/Properties.
How can I get the newVM Object from the result?
Thanks for any help.
The issue is here at this line
createdClones = result.push(newVm);
Looking at the code, the result object there is the Workflow token which
a. should not be modified
b. is a HashMap object which does not provide a push method
It seems like what you really want is to do this
createdClones.push(newVm);
Which will add your VM object to the createdClones array
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
This is the API for the Properties object/class
I've highlighted the "get" method there as this is how you extract values from the object.I can't tell you what will be in there as it depends on the workflow you have executed. If you take a look at the target workflow and check the names of the outputs then, e.g, the VM output you want is called "theNewVM", you do the following to retrieve that from the Properties
var myNewVM = outputProperties.get("theNewVM");
Handling an array of properties means you just need to iterate over the whole lot like this
// iterate over all workflow tokens and get the outputs from each
for each var(wfToken in wfTokens)
{
var outputParams = wfToken.getOutputParameters();
for each(var k in outputParams .keys)
{
System.log(k + " --> " + outputParams .get(k));
}
}
Hello eoinbyrne,
thanks for your fast reply and your very detailed answer.
I asynchronously run the vmware prebuilt Worlkflow Clone virtual machine, no customization with output newVM of Type VC:VirtualMaschine
The asynchronous Workflow run returns a WorkflowToken which is collected in a Array/WorkflowToken
After that I use the vmware prebuilt Action waitAllWorkflowComplete which returns an output actionResult of Type Array/Properties
-------------------------------------------------------------------------------------------------------------------------------------------------------
Test to get the Keys
for each (result in deleteWfsResults) {
System.debug("Result: " + result.keys);
}
>> [2019-08-23 10:49:08.493] [D] Result: __state,newVM
-------------------------------------------------------------------------------------------------------------------------------------------------------
New Test to see Value of "newVM"
for each (result in deleteWfsResults) {
System.debug("Result: " + result.keys);
System.debug("Status: " + result.__state);
System.debug("Output: " + result.newVM);
}
>> Log:
[2019-08-23 11:13:43.962] [D] Result: __state,newVM
[2019-08-23 11:13:43.964] [D] Status: completed
[2019-08-23 11:13:43.967] [D] Output: DynamicWrapper (Instance) : [VcVirtualMachine]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualMachine_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = VirtualMachine, value = vm-28578, serverGuid = null), binding = https://vcentertest.testdom:443/sdk
-------------------------------------------------------------------------------------------------------------------------------------------------------
New Test to push the "newVM" in my Array/VC:VirtualMaschine
createdClones = new Array();
for each (result in deleteWfsResults) {
System.debug("Result: " + result.keys);
System.debug("Status: " + result.__state);
System.debug("Output: " + result.newVM);
createdClones = result.push(newVm);
}
>> Log:
[2019-08-23 11:21:02.749] [D] Result: __state,newVM
[2019-08-23 11:21:02.752] [D] Status: completed
[2019-08-23 11:21:02.756] [D] Output: DynamicWrapper (Instance) : [VcVirtualMachine]-[class com.vmware.o11n.plugin.vsphere_gen.VirtualMachine_Wrapper] -- VALUE : Stub: moRef = (ManagedObjectReference: type = VirtualMachine, value = vm-28579, serverGuid = null), binding = https://vcentertest.testdom:443/sdk
[2019-08-23 11:21:02.760] [E] Error in (Workflow:Create Clones / Check Results (item7)#8) TypeError: Cannot find function push in object HashMap:31422620.
-------------------------------------------------------------------------------------------------------------------------------------------------------
After all I still dont't really understand how to deal with that "HashMap" or Object "newVM"
Eventually you can explain that a little eoinbyrne?
Mny thx and kind regards!
The issue is here at this line
createdClones = result.push(newVm);
Looking at the code, the result object there is the Workflow token which
a. should not be modified
b. is a HashMap object which does not provide a push method
It seems like what you really want is to do this
createdClones.push(newVm);
Which will add your VM object to the createdClones array
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Thank you so much eoinbyrne!
my corrected code is now:
createdClones = new Array();
for each (result in deleteWfsResults) {
createdClones.push(result.newVM);
}
thanks for your time and the fast answers!