Each script has a global variable called env, that provides access to the environment within which it runs.
These are frequently used env methods:
getParameterValue()—Obtain the value of a single-valued parameter, given the name
getParameterValues()—Obtain all of the values of a multi-valued parameter as an array, given the name
isDesktopMode()—Returns true if the script is being run on the desktop
isServerMode()—Returns true if the script is being run in EPM Workspace
createTempFile()—Create a temporary file that is removed when the script exits
getBqyDocument()—Retrieve a document from the repository, given the UUID
getFileLines()—Retrieve the content of a file from the repository as an array of strings, given the UUID
writeBqyDom()—Write a document to disk to be imported into the repository as a new version of a document or as a new document
getParameterValue() and getParameterValues() determine how the script retrieves the values the user provided for the parameters.
The two methods env.isDesktopMode() and env.isServerMode() provide information for the script about the environment it is running inside, for example, in EPM Workspace or on a desktop.
Most scripts require access to documents stored within the repository. A pseudo-repository is implemented on the desktop that provides identical methods, but that uses file system paths as pseudo-UUIDs.
The method env.getRepository() returns an object providing access to the repository. These are methods provided by the returned object:
retrieveFile()—Retrieve a file from the repository, given the UUID (This returns a Java File object pointing at a temporary file that contains the content. The temporary file is deleted when the script completes execution)
retrieveVersionedDocument()—Retrieve properties of the document stored in the repository
addVersion()—Add a version of the specified document to the repository
publishBqyFile()—Import a new document into the repository
remapOCEs()—Set up the Interactive Reporting database connection (OCE extension) mappings for a document
To make a change to a document:
Retrieve the document using repository.retrieveFile().
This writes it to a temporary file, and returns a Java File object pointing to it.
Use env.getBqyDocument(), passing the File reference.
This returns a DOM representing the content of the document.
To write the DOM back out to the disk, use env.writeBqyDocument().
Optional: To run in EPM Workspace, further steps are required:
To gain access to the properties of the specific version of the document, use
retrieveVersionedDocument().
Use versionedDocument.sectionOCEPairInfos().
To retrieve the UUID of the parent folder that contains the document, call versionedDocument.getParentIdentity().
To retrieve section OCEs, use getSectionOCEMapping() on the versioned document.
Optional: To update the OCEs associated with data models, use remapOCEs().
Upload the modified document to the repository by using addVersion() to create a new version of the original document, or publishBqyFile() to store it as a new document.
As an example, see Using the SortDataModelTopics Script.