Use Case: Add a New Workflow Step
In this use case, you will create a complete new workflow step that updates the Tactic Comment field with a new specified value that you will send as input.
-
Go to Business Object APIs tab and navigate to the “Promotion” entry. If it does not exist, create a new record with those attributes.
-
You need to configure the BO API Output entities. The Output entities for a BO API define which kind of objects the API works with. Since you’re working with promotions and tactics, you need to add the related ones. In the “Output Entities” related 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 new workflow with the following attributes:
- Name: updateTacticComments
- Description: Updates Tactic Comments with the input parameters.
-
Navigate to your new workflow record.
-
We need to configure how the input records are going to be mapped to the output records. To do so, you will 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 our workflow. To load all the required promotion data, you 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
-
-
At this point, you’ll have a functional new API that reads the promotion and saves it. You can check the input payloads structure for this API by clicking the View Schema button on the Workflow header. The sample schema is provided below.
-
Add custom behavior. To add additional workflow steps, you need to create APEX classes that implement the behavior. For our example, you are going to 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.
-
After creating the apex class, you need to create the BO API Workflow Step record. To do so, 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 you want to apply this step on each Input Tactic)
- Sales Org: 0001
-
After Creating the Workflow Step, you need to define which input structures the step needs. To do so, create new records in the Step Input Structures related list of the Workflow Step. Since our example uses an Attribute called MyComment, you should add a definition for it. The attributes for the Step input structures are used to determine the schema for the input. 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
-
After creating your step input structure, you can go back to your Workflow record and add it as a Workflow Step.
- Business Object API Workflow Step: SetCommentValue
- Enabled: checked
- Sort: 30
-
Click again on View Schema and the following is displayed.
-
Test the API by sending a request to the Promotion BO API endpoint and passing the required parameters.
POST /services/apexrest/cgcloud/promotions/ingest
-
After sending the request, you can track the execution status from the Business Object API Transaction Logs tab by referencing the request through the returned import Id.