var vCAC_Machine = Server.findAllForType("vCAC:VirtualMachine","VMUniqueID eq '" + vm.config.instanceUuid + "'"); var virtualMachineEntity = vCAC_Machine[0].getEntity(); //to get entity var vmEntityProps = virtualMachineEntity.getProperties(); //to get Entity properties for the next step vmEntityProps.remove('VMDNSName'); vmEntityProps.put('VMDNSName', newName); vmEntityProps.put("VirtualMachineName", newName); var hostId = virtualMachineEntity.hostId; var modelName = virtualMachineEntity.modelName; var entitySetName = virtualMachineEntity.entitySetName; var entityIdString = virtualMachineEntity.keyString; //Magic! var Entity_Update = System.getModule("com.vmware.library.vcac").updateVCACEntity(hostId,modelName,entitySetName,entityIdString,vmEntityProps,null,null); var VM_update_Hostname = System.getModule("com.vmware.library.vcac").addUpdatePropertyFromVirtualMachineEntity(vCAC_host,virtualMachineEntity,"Hostname",newName,false,false,false,false); //bind variables var workflowPath = 'Library/vCenter/Virtual Machine management/Basic'; var workflowNameToInvoke = 'Rename virtual machine'; //create execution properties var executionProperties = new Properties(); executionProperties.put('newName',newName); executionProperties.put('vm',vm); //find worfklow catagory and get all workflows var workflows = Server.getWorkflowCategoryWithPath(workflowPath).allWorkflows; //loop over each workflow and find the workflow based on name for each(var workflowObject in workflows){ if(workflowNameToInvoke == workflowObject.name){ //execute workflow and get workflowToken var currentToken = workflowObject.execute(executionProperties) //wait for workflow completions var complete = false; while(complete == false){ if(currentToken != null && (currentToken.state != "running" && currentToken.state != "waiting")){ System.log("Workflow '"+currentToken.name+"' terminated with status '"+currentToken.state+"'"); complete = true; } } //get output from the workflow token var outputPropertiesToken = currentToken.getOutputParameters() System.log('outputPropertiesToken.keys: ' + outputPropertiesToken.keys) System.log("outputPropertiesToken.get('stringOutput'): " + outputPropertiesToken.get('stringOutput')) break; } } for each(var workflowObject in workflows){ if(workflowNameToInvoke == workflowObject.name){ //execute workflow and get workflowToken var currentToken = workflowObject.execute(executionProperties) //wait for workflow completions var complete = false; while(complete == false){ if(currentToken != null && (currentToken.state != "running" && currentToken.state != "waiting")){ System.log("Workflow '"+currentToken.name+"' terminated with status '"+currentToken.state+"'"); complete = true; } } break; } }