The Scripting Environment

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() 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:

  To make a change to a document:

  1. Retrieve the document using repository.retrieveFile().

    This writes it to a temporary file, and returns a Java File object pointing to it.

  2. Use env.getBqyDocument(), passing the File reference.

    This returns a DOM representing the content of the document.

  3. Modify the DOM.

  4. To write the DOM back out to the disk, use env.writeBqyDocument().

  5. Optional: To run in EPM Workspace, further steps are required:

    1. To gain access to the properties of the specific version of the document, use

      retrieveVersionedDocument().

    2. Use versionedDocument.sectionOCEPairInfos().

    3. To retrieve the UUID of the parent folder that contains the document, call versionedDocument.getParentIdentity().

    4. To retrieve section OCEs, use getSectionOCEMapping() on the versioned document.

    5. Optional: To update the OCEs associated with data models, use remapOCEs().

    6. 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.