Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Enum attribute value -> string
  • Responsibility attribute value -> string
  • Numeric attribute value -> number
  • Text attribute value -> string
  • Date attribute value -> Date
  • Date interval value - > Object o with o.from (Date) and o.to (Date)
  • Boolean attribute value -> boolean

    Note

    Start and end dates of date intervals can depend on date attributes. If a plugin changes such a start or end date the change is ignored. The value can only be changed via the corresponding date attribute.

Working with arrays

The setValues()-function expects an array 'values' which has to be a string array. Although the reaction script is JavaScript, how this array needs to be created depends on the version of the used JRE/JDK (Java Runtime Environment).

JDK 1.7

The array must be created as shown in this code-snippet:

Code Block
languagejs
titleExample
var complexitySet = ["low"];
changedObject.setValues("Complexity", complexitySet);
JDK 1.8

The array must be created as shown in this code-snippet:

Code Block
languagejs
titleExample
var StringArrayType = Java.type("java.lang.String[]");
var complexitySet = new StringArrayType(1);
complexitySet[0] = "low";
changedObject.setValues("Complexity", complexitySet);

Helper Functions

HTTP

From reaction scripts it is possible to perform Http(s)-calls to third-party REST APIs. Using "http" with various commands will provide such functionality. 

Function (of api.http)Description
setURL(string URL)Sets URL to which http call will be performed
setMethod(string method)Sets request method type. There are four possible options: GET, PUT, POST, DELETE.
addUserName(string password)Sets username to credentials within rest request.
addPassword(string password)Sets password to credentials within rest request.
setContentType(string contentType)Sets content type for the request. By default it is "application/json".
setBody(string body)Sets body for the request. By default it is JSON body.
addParameter(string name, string value)Adds parameter for the request.
addHeader(string name, string value)Adds header for the request.
performRequest()If all needed data is set, performs http request. Returns response as String.
toJsonObject(string stringInJson)Converts string if it is in json format to JSON object. Helping function to convert response to json if needed.
toJsonArray(string stringinJson)Converts string if it is in json format to JSON array. Helping function to convert response to json if needed.
setProxyURL(string proxyURL)Sets proxy URL
setProxyUser(string proxyUser)Sets username to proxy credentials.
setProxyPassword(string proxyPassword)Sets password to proxy credentials.

Send EMail

It's possible to send emails from within a script:

Function (of api)Description
sendEmail(string recipient, string subject, string content)

With this function it is possible to send emails as a plain text. Returns an integer value of 1 if email was sent successfully, -1 if not.

Please see the Subscriptions for more information on how to configure mail Mail-notifications.

User

There is a function to get information about user by username:

...

FunctionDescription

getId()

Returns id.
getLoginName()Returns login name.
getFirstName()Returns first name.
getLastName()Returns last name.
getEmail()Return email address.
setLoginName(String loginName)Sets new login name and returns true if operation was successful and false if not.
setFirstName(String firstName)Sets new first name and returns true if operation was successful and false if not.
setLastName(String lastName)Sets new last name and returns true if operation was successful and false if not.
setEmail(String email)Sets new email address and returns true if operation was successful and false if not.


History

To work with the history there are two available functions:

Function (of api)Description
getHistoryForType(String typePersistentName)returns history for Building Block Type
getHistoryForBuildingBlock(Integer buildingBlockId, String typePersistentName)returns history for Building Block

Building Block Type history

The object that represents the Building Block Type history has the following properties:

...

FunctionDescription
getBuildingBlockIdentityString()returns identify string for Building Block
getBuildingBlockID()return ID for Building Block

Building Block history

The object that represents the history for a Building Block has the following properties:

...

FunctionDescription
getRelationName()returns persistent name of the relation
getRelatedElementName()returns related element name
getChangeType()returns type of change
getFeaturePersistentName()returns persistent name of Building Block
getAdded()returns array of added objects
getRemoved()returns array of removed objects
isMultipleValue()returns if Building Block has multiple value

Reaction Event

Reaction events only occur in subscription scripts. A reaction event is an array containing all changes for a certain Building Block Type.

...

  • Change for a single assignment attribute: The removed/added attribute value, or null
  • Change for a multi assignment attribute: Array of the removed/added attribute values
  • Change for a single assignment relation: The ID of the removed/added Building Block, or null
  • Change for a multi assignment relation: Array of the IDs of the removed/added Building Blocks

Example

The assigned Business Units of a Business Domain "Management" change from "Executive Board" (ID: 10) and "Human Resource Management" (ID: 11) to "Executive Board" (ID: 10) and "R&D Management" (ID: 21). The according BuildingBlockChange will then look as follows:

...

Code Block
var businessDomain = api.datamodel.findByTypeAndId("BusinessDomain", bbChangeObject.id);
var assignedBusinessUnits = businessDomain.getRelatedObjects("businessUnits");

Anchor
pluginApiDate
pluginApiDate
Date

To create dates that can be used as attribute values or within date intervals the function api.createDate() has to be used. Directly creating dates in the script via "new Date()" does not work. The arguments for this functions can be:

...