Trade Promotion Management Transformation Engine Workflows
The workflow comprises APEX callable class to apply the transformations from the input JSON into the output structure.
Business object API workflow rules use the concept of Entities to identify records in both the data input (input payloads) and output (generated objects or records). The supported entities on the engine can be found on the business object API entities object. The ones provided by the managed package are:
| Entity Name | Location | Description |
|---|---|---|
Promotion | Input | Represents the input Promotion. The attributes for the object are defined in the Workflow Rules that use this Entity. |
Tactic | Input | Represents an input Tactic. The attributes for the object are defined in the Workflow Rules that use this Entity. |
ManualInputs | Input | Represents a Manual Inputs Array. The attributes for the object are defined in the Workflow Rules that use this Entity. |
ProductFilter | Input | Represents a Product Filter Structure. The attributes for the object are defined in the Workflow Rules that use this Entity. |
TPM_Promotion | Output | Represents the TPM_Promotion Instance with all the promotion data. |
TPM_Promotion.Promotion | Output | Represents a TPM_Promotion.Record instance with all the Promotion SObject Data. SObject fields can be used with dot notation. |
TPM_Promotion.Tactic | Output | Represents a TPM_Promotion.TacticRecord instance with all the Tactic SObject Data. SObject fields can be used with dot notation. |
TPM_Promotion.Attachment | Output | Represents a TPM_Promotion.Record instance with all the Promotion Attachment SObject Data. SObject fields can be used with dot notation. |
TPM_Promotion.AttachmentLink | Output | Represents a TPM_Promotion.Record instance with all the Promotion Attachment Link SObject Data. SObject fields can be used with dot notation. |
TPM_Promotion.ProductFilter | Output | Represents a TPM_ProductFilter instance with all the Promotion Product filter information. |
TPM_Promotion.ProductShare | Output | Represents a TPM_Promotion.Record instance with all the Promotion Product Share SObject Data. SObject fields can be used with dot notation. |
TPM_Promotion.TacticConditionCreationDefinition | Output | Represents a TPM_Promotion.Record instance with all the Tactic Condition Creation Definition SObject Data. SObject fields can be used with dot notation. |
TPM_Promotion.TacticFund | Output | Represents a TPM_Promotion.Record instance with all the Tactic Fund SObject Data. SObject fields can be used with dot notation. |
TPM_Promotion.TacticProductFilter | Output | Represents a TPM_ProductFilter instance with all the Tactic Product filter information. |
CustomState | Output | Represents a generic Object that is passed to the Promotion Saving Process while saving. |
Workflow Step SObject
Workflow steps are defined in the Workflow StepSObject. Each step requires the following series of attributes:
| Object | Description | Required/Optional |
|---|---|---|
Name | Name of the business rule. | Required |
Entity | Entity of the Input the rule must be applied to. | Optional |
Method | Action method that is passed to the callable class. | Optional |
Classname | Name of the APEX Callable class implementing the transformation. | Required |
Description | High-level overview of what the rule does | Optional |
Input Structure records
Every rule must have a list of input structure records that reflect the expected inputs for the rule. Each record requires the following information:
| Object | Description |
|---|---|
Path | Path of the input JSON, in which the rule reads a value. Possible values are:
|
Required | Boolean to indicate if the property is mandatory or optional. |
RecordType | The type of the input expected for the property. Possible values are:
|
The input structure records are used to generate the JSON schema. If an input attribute received isn’t as per the rules, the step reports an error.
Applied Transformation Rules
Applied Transformation Rules are configured in the Transformation Configuration Record. The following table provides information about the record fields that must be updated:
| Object | Description |
|---|---|
Transformation Rule | Transformation rule to be applied. |
Enabled | Indicates whether the rule is applied or not. |
Sort | Rules are executed in ascending order (allows the creation of dependencies). |
Transformation Rules APEX classes receive a context object with the following attributes:
Create a complete new workflow that to update the Tactic Comment field with a new specified value.
-
Navigate to Business Object APIs Tab and navigate to the
Promotionentry for Sales Org 0001. If it does not exist, create a record with those attributes. -
Configure the BO API Output entities. The Output entities for a BO API define which kind of objects the API works with. In the
Output Entitiesrelated list, ensure the following entities are displayed. If not present in the related list, add them:- TPM_Promotion (Main promotion object wrapper)
- TPM_Promotion.Tactic (Tactic Records)
- TPM_Promotion.Promotion (Promotion Record)
-
In the workflows tab, create a workflow with the following attributes:
- Name: updateTacticComments
- Description: Updates Tactic Comments with the input parameters
-
Navigate to your new workflow record.
-
Configure how the input records are going to be mapped to the output records. To do so, add entries to the “Input Entities and Mapping” related list. Create the following records in the related list.
Record 1
- Business Object API Entity: Promotion
- Output Entity: TPM_Promotion.Promotion
- Input Mapping Field: Id
- Output Mapping Field: Id, cgcloud__ExternalId__c
Record 2
- Business Object API Entity: Tactic
- Output Entity: TPM_Promotion.Tactic
- Input Mapping Field: Id
- Output Mapping Field: Id, cgcloud__ExternalId__c
-
Add Steps into the workflow. To load all the required promotion data, we can reuse Managed Package provided workflow steps. In the Workflow Steps related list, create the following records:
Record 1
- Business Object API Workflow Step: loadPromotionDefaults(update)2
- Enabled: checked
- Sort: 10
Record 2
- Business Object API Workflow Step: loadTacticDefaults(update)2
- Enabled: checked
- Sort: 20
-
Check the input payloads structure for this API by clicking the “View Schema” button on the Workflow header. The schema should look like:
-
Add custom behavior. To add additional workflow steps create an APEX class that copies an input attribute from the input into the SObject Field Comment__c. Create the following APEX class in your org:
-
Create the BO API Workflow Step record. Navigate to the “Business Object API Workflow Steps” Tab and create a new Record:
- Business Object API Workflow Step Name: SetCommentValue
- Classname: SetCommentValue (Name of the APEX class)
- Description: Sets the Comment Value for Tactic from the input attributes.
- Method: test (Method is passed to the callable class. This way, with different methods, the same class can implement multiple behaviors)
- Entity: Tactic (Since we want to apply this step on each Input Tactic)
- Sales Org: 0001
-
Define which input structures the step needs. Create records in the Step Input Structures related list of the Workflow Step. The attributes for the Step input structures are used to determine the schema that the input should have (View Schema button). If the input does not match the schema, an error is displayed.
- RecordType String
- Description: New Comment Attribute value
- Path: .MyComment
- Required: unchecked
- Maximum Length: 80
-
Add a Workflow step into the Workflow record.
- Business Object API Workflow Step: SetCommentValue
- Enabled: checked
- Sort: 30
-
Click View Schema and the schema should have the following structure. The schema accpets the new
MyCommentattribute. -
Test the API by making a REST call to the Promotion BO API endpoint and passing the required parameters.
-
Track the execution status from the “Business Object API Transaction Logs” Tab by referencing the request by the returned importId.
- Avoid expensive operations (such as significant JSON serializations or deserializations) in the
Business Rulescode. - Cache the SObject records from the database, as other rules might be impacted. (check
SimplePromotionCoreBusinessRules.readSObjectById) - Ensure that the
Business Rulesfocus on a single job, to enable a modular and configurable approach.