...
Code Block | ||
---|---|---|
| ||
let log = context.getLogger(); log.info("Guard currently executing"); |
Accessing Concept Data
Scripts can access concept data in two forms: the version persisted in the database and, in the case of Guard Scripts, the prospective version that includes pending changes. These versions are accessed through the execution context provided by the internal JavaScript API.
Access Methods
Persisted Concept: Represents the concept as it is currently stored in the database. Accessed with:
Code Block language js let persistedConcept = context.getPersistedConcept();
Current Concept (Guard Scripts only): Represents the concept with pending changes that will be saved if the guard script allows it. Accessed with:
Code Block language js let currentConcept = context.getCurrentConcept();
Example Script
The following example script demonstrates how a Guard Script might use these methods to check if the title of a concept has been changed and, if so, logs the change and decides whether to allow the update:
Code Block | ||
---|---|---|
| ||
let log = context.getLogger();
let persistedConcept = context.getPersistedConcept();
let currentConcept = context.getCurrentConcept();
let persistedTitle = persistedConcept.getTitle();
let currentTitle = currentConcept.getTitle();
log.info("Checking title change for approval...");
if (currentTitle !== persistedTitle) {
log.info("Title change detected: from '" + persistedTitle + "' to '" + currentTitle + "'.");
// Additional conditions can be checked here
return true; // Allow the update
} else {
log.info("No title change detected.");
return false; // Prevent the update if no changes are made to the title
} |
In this script, the getTitle()
method is used to retrieve the title from both the persisted and current concept instances, allowing the script to compare them and decide based on business rules whether to allow the update.
Concept Object Methods
The Concept
object provides several methods that enable scripts to interact with concept data effectively. These methods are available across all types of concepts within the application, ensuring a consistent interface for script developers.
Available Methods
Below is a list of methods that scripts can access to retrieve and manipulate data from any concept (configuration area, unit, configuration and configuration item):
Method | Return Type | Description |
---|---|---|
|
| Retrieves the unique identifier of the concept. |
|
| Retrieves the title of the concept. |
|
| Retrieves the description of the concept. |
|
| Retrieves the key that identifies the concept type. |
|
| Retrieves the key that identifies the concept state. |
|
| Retrieves the timestamp when the concept was archived. |
|
| Retrieves a list of tags associated with the concept. |
|
| Retrieves the concept type of the concept |
Accessing Properties and Complex Properties
The Concept
object offers methods to retrieve simple properties and complex properties (also known as records) in various data types.
Simple Property Access Methods
These methods allow you to retrieve simple properties directly from a concept in different data types. The methods that return the property as their type throw an exception if the property doesn’t actually have this type:
Method | Return Type | Description |
---|---|---|
|
| Retrieves a property by its key as a string. This method is always available, no matter the data type of the property. |
|
| Retrieves an integer property value by its key. |
|
| Retrieves a double property value by its key. |
|
| Retrieves a BigDecimal property value by its key. |
|
| Retrieves a boolean property value by its key. |
|
| Retrieves an instant (timestamp) property value by its key. |
|
| Retrieves a long property value by its key. |
Complex Property (Record) Access Methods
Complex properties are accessed via the getComplexProperty(String recordTypeKey)
method, which retrieves a list of ComplexProperty
objects. Each ComplexProperty
can hold multiple properties of various types.
Methods Available in ComplexProperty
Method | Return Type | Description |
---|---|---|
|
| Retrieves a string property value by its index and key within the complex property. (Always available) |
|
| Retrieves an integer property value by its index and key. |
|
| Retrieves a double property value by its index and key. |
|
| Retrieves a boolean property value by its index and key. |
|
| Retrieves a BigDecimal property value by its index and key. |
|
| Retrieves a long property value by its index and key. |
|
| Retrieves an instant property value by its index and key. |
ConceptType Object Methods
The Concept
object also includes access to its associated concept type through the ConceptType
, which carries detailed type-specific information. This is crucial for scripts that need to adapt their behavior based on the type of the concept they are interacting with.
Available Methods
Below is a list of methods provided by the ConceptType
object, accessible through the Concept
object:
Method | Return Type | Description |
---|---|---|
|
| Retrieves the base kind of the concept type, indicating its general classification. |
|
| Retrieves the key for any associated child concept type. |
|
| Retrieves a list of keys for the property types defined for this concept type. |
|
| Retrieves a list of keys for the record types defined for this concept type. |
|
| Retrieves the key for the state machine associated with this concept type, if any. |
Accessing Master Data
Scripts have the capability to access and utilize master data, which are tables of fixed data independent of the concept units. Master data provides a stable dataset that scripts can rely on for performing various operations, such as validations and computations.
...
Below is a description of the methods available on the MasterDataTable
object. This object encapsulates the structure and data of a master data table, which includes its columns and rows.
Method | Return Type | Description |
---|---|---|
|
| Retrieves the unique identifier of the master data table. |
|
| Retrieves the key associated with the master data table. |
|
| Retrieves the title of the master data table. |
|
| Retrieves a list of columns within the table. |
|
| Retrieves a list of rows within the table. |
|
| Retrieves the creation context of the table. |
|
| Retrieves the last modified context of the table. |
Below is a table describing the methods available on the MasterDataColumn
object, which represents a column within a master data table.
Method | Return Type | Description |
---|---|---|
|
| Retrieves the unique key identifier of the column. |
|
| Retrieves the title or name of the column. |
|
| Retrieves the data type of the column's values. |
Here's a table that outlines the methods accessible on the MasterDataRow
object, which encapsulates a row within a master data table.
Method | Return Type | Description |
---|---|---|
|
| Retrieves the unique identifier of the row. |
|
| Retrieves the key associated with the row. |
|
| Retrieves the title of the row. |
|
| Retrieves a list of cells contained in the row. |
|
| Retrieves the creation context of the row. |
|
| Retrieves the last modified context of the row. |
Lastly, the following table describes the methods on the MasterDataCell
object, which represents individual cells within a master data row.
Method | Return Type | Description |
---|---|---|
|
| Retrieves the key identifying this cell in the row. |
|
| Retrieves the value held by this cell. |