Certain situations require you to uniquely identify a system object record, such as a task or history record, that does not have a relationship to the current object record. To work around this situation, you can add a custom field to a record and store the primary key of another record to create a relationship. When you need to retrieve a record, you can use the primary key in this field. Typically, users do not see or modify this field.
For example, you might have a rule that creates a history record when someone creates a particular task for a project. After the task is complete, another rule might retrieve the history record and update it. In this situation, the project's history and the task have no direct relationship. To create a relationship, you can use the first rule to create a custom field in the task object definition and store the primary key of the history record. When you need to retrieve that history record in the second rule, you can use the custom field value.
The following code snippet demonstrates how the first rule retrieves the primary key of the history record and stores it in the custom field of a task:
// Store the primary key of the history in the record's custom field task.setNumberFieldValue("history", new BigDecimal(history.getPrimaryKey())); |
The following code snippet demonstrates how a different rule retrieves the history record using its primary key in the custom field of a task record:
// Retrieving the primary key of the history from the record's custom field Long primaryKey = record.getNumberFieldValue("history").longValue();
// Retrieve the related history record History retrievedHistory = platform.getHistoryService().read(primaryKey); |