4.0

Table Of Contents
Setting and Obtaining Properties from a Hashtable
The following JavaScript example sets properties in a hashtable and obtains the properties from the hashtable.
In the following example, the key is always a String and the value is an object, a number, a Boolean, or a String.
var table = new Properties() ;
table.put("myKey",new Date()) ;
// get the object back
var myDate= table.get("myKey") ;
System.log("Date is : "+myDate) ;
Replace the Contents of a String
The following JavaScript example replaces the content of a String and replaces it with new content.
var str1 = "'hello'" ;
var reg = new RegExp("(')", "g");
var str2 = str1.replace(reg,"\\'") ;
System.log(""+str2) ; // result : \'hello\'
Compare Types
The following JavaScript example checks whether an object matches a given object type.
var path = 'myurl/test';
if(typeof(path, string)){
throw("string");
else {
throw("other");
}
Run a Command in the Orchestrator Server
The following JavaScript example allows you to run a command line on the Orchestrator server. Use the same
credentials as those used to start the server.
NOTE Access to the file system is limited by default. To access the file server from Orchestrator, see “Accessing
the Orchestrator Server File System from JavaScript and Workflows,” on page 121.
var cmd = new Command("ls -al") ;
cmd.execute(true) ;
System.log(cmd.output) ;
Email Scripting Examples
Workflow scripted elements, actions, and policies require scripting of common email-related tasks. You can
cut, paste, and adapt these examples into your scripted elements.
Obtain an Email Address
The following JavaScript example obtains the email address of the current owner of a running script.
var emailAddress = Server.getRunningUser().emailAddress ;
Chapter 4 Scripting
VMware, Inc. 125