VMware Cloud Community
demhyt
Contributor
Contributor
Jump to solution

Get output parameter from workflow using soap in PHP

Hi all, I have a question about how to print the parameter output in php using soap protocol.....I create the workflow with only 1 scriptable task with vms variable name as output parameter like this,

var sdkConnections = VcPlugin.allSdkConnections;

vms = new Array();

for (var i in sdkConnections) {

  var host = sdkConnections[i];

  var found;

  if (host.isInventoryServiceAvailable()) {

  found = host.getAllVirtualMachines();

  }

  for (var j in found) {

  vms.push(found[j]);

  System.log(vms);

  }

}

And my php source code like this,

<?php

include ("parameters.inc");

$vco = new SoapClient('https://' . $vco_server . ':8281/vmware-vmo-webcontrol/webservice?WSDL');

$workflowid = "f73f2521-0e6b-48e8-81b9-388b13fc3fea";

$param = array(workflowId=>$workflowid,username=>$vco_user,password=>$vco_pass);

echo '<br>';

$result3 = $vco->executeWorkflow($param);

print_r($result3);

echo '<br>';

foreach ($result3 as $token)

{

        $tokenID = $token->id;

}

$param2 = array(workflowTokenId=>$tokenID,username=>$vco_user,password=>$vco_pass);

$wftokenstatus = $vco->getWorkflowTokenStatus($param2);

print_r($wftokenstatus);

echo '<br>';

$wftokenresult = $vco->getWorkflowTokenResult($param2);

print_r($wftokenresult);

echo '<br>';

?>

When I try to running in web the output like this,

stdClass Object ( [executeWorkflowReturn] => stdClass Object ( [id] => ff808081440b6eb90144316de4bc04fe [title] => Copy of Get virtual machines by name [workflowId] => f73f2521-0e6b-48e8-81b9-388b13fc3fea [currentItemName] => __item-undefined__ [currentItemState] => running [globalState] => running [businessState] => [startDate] => 20140215002449+0700 [endDate] => [xmlContent] =>         ) )

stdClass Object ( [getWorkflowTokenStatusReturn] => )

stdClass Object ( [getWorkflowTokenResultReturn] => stdClass Object ( [name] => vms [type] => VC:VirtualMachine [value] => ) )

I see in orchestrator client, my workflow running smoothly and in Logs tab I can see all of my VM appear but I try to print all array component in my php script using print_r(), the object value always null, only can get name and type like in above....Any idea how to get the output parameter value?..thanks before

0 Kudos
1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

Change this code of yours:

for (var j in found) {

  vms.push(found[j]);

  System.log(vms);

  }

To this:

for (var j in found) {

  vms.push(found[j].name);

  System.log(vms);

  }

In that code, j is a VC:VirtualMachine object, so instead of pushing the whole object into your array, just push the .name property of the vm. Also, be sure that your output variable is of type: Array of Strings

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

0 Kudos
7 Replies
demhyt
Contributor
Contributor
Jump to solution

I think I found the answer with adding the sleep element in my workflow but the output become like this,

stdClass Object ( [getWorkflowTokenResultReturn] => stdClass Object ( [name] => vms [type] => Array/Any [value] => #{#VC:VirtualMachine#dunes://service.dunes.ch/CustomSDKObject?id='vcenter.lab.local/vm-9024'&dunesName='VC:VirtualMachine'#;#VC:VirtualMachine#dunes://service.dunes.ch/CustomSDKObject?id='vcenter.lab.local/vm-456'&dunesName='VC:VirtualMachine'#;#VC:VirtualMachine#dunes://service.dunes.ch/CustomSDKObject?id='vcenter.lab.local/vm-7862'&dunesName='VC:VirtualMachine'#;#VC:VirtualMachine#dunes://service.dunes.ch/CustomSDKObject?id='vcenter.lab.local/vm-9021'&dunesName='VC:VirtualMachine'#;#VC:VirtualMachine#dunes://service.dunes.ch/CustomSDKObject?id='vcenter.lab.local/vm-9020'&dunesName='VC:VirtualMachine'#;#VC:VirtualMachine#dunes://service.dunes.ch/CustomSDKObject?id='vcenter.lab.local/vm-9023'&dunesName='VC:VirtualMachine'#;#VC:VirtualMachine#dunes://service.dunes.ch/CustomSDKObject?id='vcenter.lab.local/vm-451'&dunesName='VC:VirtualMachine'#;#VC:VirtualMachine#dunes://service.dunes.ch/CustomSDKObject?id='vcenter.lab.local/vm-450'&dunesName='VC:VirtualMachine'#;#VC:VirtualMachine#dunes://service.dunes.ch/CustomSDKObject?id='vcenter.lab.local/vm-5202'&dunesName='VC:VirtualMachine'#;#VC:VirtualMachine#dunes://service.dunes.ch/CustomSDKObject?id='vcenter.lab.local/vm-5203'&

I curious how to "convert" VC:VirtualMachine type into normal string??...

0 Kudos
mcfadyenj
Hot Shot
Hot Shot
Jump to solution

there is also the async callback methods you can use.

there are a couple of interesting methods such as

onXxxxxxXCompleted events.


0 Kudos
d-fens
Enthusiast
Enthusiast
Jump to solution

Hi demhyt, you write that you wanted to create a workflow that returns an array with the names of all VirtualMachines but it seems that you return an array of VirtualMachine objects. That certainly is a datatype that your PHP script does not necessarily understand (these are just pointers to the repository within vCO). If the main purpose of the workflow is to only return the names I would just do so and return an array of strings with the names. You might add a switch as an input parameter what to actually return (names<->VMs) if you have other workflows that are interested in the real VM objects.

Regards, Ronald.

Ronald Rink d-fens GmbH
0 Kudos
igaydajiev
VMware Employee
VMware Employee
Jump to solution

WorkflowToken state is still running.

You need to wait until the state becomes  ("completed", "failed" or "canceled") before trying to get the output variables.

not sure for exact PHP syntax but something like

while ( $wftokenstatus->globalState != "completed" || $wftokenstatus->globalState !=  "failed" || $wftokenstatus->globalState !=  "canceled") {

     sleep(2000);

    $wftokenstatus = $vco->getWorkflowTokenStatus($param2);

}

print_r($wftokenstatus);

$wftokenresult = $vco->getWorkflowTokenResult($param2);

Burke-
VMware Employee
VMware Employee
Jump to solution

Change this code of yours:

for (var j in found) {

  vms.push(found[j]);

  System.log(vms);

  }

To this:

for (var j in found) {

  vms.push(found[j].name);

  System.log(vms);

  }

In that code, j is a VC:VirtualMachine object, so instead of pushing the whole object into your array, just push the .name property of the vm. Also, be sure that your output variable is of type: Array of Strings

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
demhyt
Contributor
Contributor
Jump to solution

That's work like a charm!!!...thanks Burke, how I determine the array structure like name value you mention in your source code?

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

To identify the possible properties for a given object (in this case you are working with VC:VirtualMachine objects), look up the object in the API explorer. It shows the properties like name as well as the methods available for a given object. It also provides links to resulting object types so that you may inspect available properties/methods of those as well.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos