4.0

Table Of Contents
Send an Email
The following JavaScript example sends an email to the defined recipient, through an SMTP server, with the
defined content.
var message = new EmailMessage() ;
message.smtpHost = "smtpHost" ;
message.subject= "my subject" ;
message.toAddress = "receiver@vmware.com" ;
message.fromAddress = "sender@vmware.com" ;
message.addMimePart("This is a simple message","text/html") ;
message.sendMessage() ;
File System Scripting Examples
Workflow scripted elements, actions, and policies require scripting of common file system tasks. You can cut,
paste, and adapt these examples into your scripted elements.
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.
Add Content to a Simple Text File
The following JavaScript example adds content to a text file.
var tempDir = System.getTempDirectory() ;
var fileWriter = new FileWriter(tempDir + "/readme.txt") ;
fileWriter.open() ;
fileWriter.writeLine("File written at : "+new Date()) ;
fileWriter.writeLine("Another line") ;
fileWriter.close() ;
Obtain the Contents of a File
The following JavaScript example obtains the contents of a file from the Orchestrator server host machine.
var tempDir = System.getTempDirectory() ;
var fileReader = new FileReader(tempDir + "/readme.txt") ;
fileReader.open() ;
var fileContentAsString = fileReader.readAll();
fileReader.close() ;
LDAP Scripting Examples
Workflow scripted elements, actions, and policies require scripting of common LDAP tasks. You can cut, paste,
and adapt these examples into your scripted elements.
Convert LDAP Objects to Active Directory Objects
The following JavaScript example converts LDAP group elements to Active Directory user group objects, and
the reverse.
var ldapGroup ;
// convert from ldap element to Microsoft:UserGroup object
var adGroup = ActiveDirectory.search("UserGroup",ldapGroup.commonName) ;
// convert back to LdapGroup element
var ldapElement = Server.getLdapElement(adGroup.distinguishedName) ;
vCenter Orchestrator Developer's Guide
126 VMware, Inc.