4.1

Table Of Contents
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) ;
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");
Chapter 4 Scripting
VMware, Inc. 123