4.1

Table Of Contents
Networking Scripting Examples
Workflow scripted elements, actions, and policies require scripting of common networking tasks. You can cut,
paste, and adapt these examples into your scripted elements.
Obtain Text from a URL
The following JavaScript example accesses a URL, obtains text, and converts it to a string.
var url = new URL("http://www.vmware.com") ;
var htmlContentAsString = url.getContent() ;
vCenter Server Scripting Examples
Workflow scripted elements can include scripting of common vCenter Server tasks. You can cut, paste, and
adapt these examples into your scripted elements.
You can consult an online version of the Scripting API for the vCenter server plug-in on the Orchestrator
documentation home page.
Access Managed Object Types
The following JavaScript example allows Orchestrator to use scripting to access vCenter Server managed
objects through the vCenter Server plug-in.
var vm = ...;
// Get the property 'name'
var name = vm.name; // returns a string
// return a VcEnvironmentBrowser managed object
var environmentBrowser = vm.environmentBrowser;
Access Managed Object Reference Types
The following JavaScript example allows Orchestrator to access data objects with the return type
ManagedObjectReference. Getters and setters that end with
_ManagedOjects
return
ManagedObject
or
List<ManagedObjects>
.
// virtualMachine is a workflow input parameter
var virtualMachineSnapshotInfo = virtualMachine.snapshot;
var virtualMachineSnapshot = virtualMachineSnapshotInfo.currentSnapshot;
// The reverse operation
virtualMachineSnapshotInfo.currentSnapshot = virtualMachineSnapshot;
In versions of Orchestrator earlier than 4.1, you must use the toManagedObject() method to convert object
references, for example workflow input parameter objects, to managed objects. The following JavaScript
operation works in Orchestrator 4.1, but it is no longer necessary.
// vCenter Server 4.0 plug-in code
var virtualMachineSnapshot = VcPlugin.toManagedObject(
virtualMachine, virtualMachineSnapshot);
vCenter Orchestrator Developer's Guide
124 VMware, Inc.