4.0

Table Of Contents
Logging Scripting Examples
Workflow scripted elements, actions, and policies require scripting of common logging tasks. You can cut,
paste, and adapt these examples into your scripted elements.
Persistent Logging
The following JavaScript example creates persistent log entries.
Server.log("This is a persistant message", "enter a long description here");
Server.warn("This is a persistant warning", "enter a long description here");
Server.error("This is a persistant error", "enter a long description here");
Non-Persistent Logging
The following JavaScript example creates non-persistent log entries.
System.log("This is a non-persistant log message");
System.warn("This is a non-persistant log warning");
System.error("This is a non-persistant log error");
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, actions, and policies require scripting of common vCenter Server tasks. You can
cut, paste, and adapt these examples into your scripted elements.
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. You must use the toManagedObject() method to convert workflow input parameter
objects to managed objects.
// VcVirtualMachineSnapshotInfo data object
var virtualMachineSnapshotInfo = virtualMachine.snapshot;
// There is no automatic conversion between ManagedObjectReference and VimManagedObject
Chapter 4 Scripting
VMware, Inc. 127