You are here:
Create a Definition to Calculate Purchase Credit and Reward
The Cloud Kicks admin created and activated a Data Processing Engine definition to calculate and update the purchase credit for accounts based on their orders. The definition is also used to calculate the bonuses to be awarded to the salespeople associated with the orders.
Required Editions
| View supported editions. |
The admin uses Order and Contact as the data source objects. The purchase credit for accounts is written back to a custom field in the Account object, and the employee bonus is written back to the custom object Salesperson Bonus. The definition uses two input variables to ensure that the orders that were effective and closed during a specific financial year are considered. The input variable values aren't defined, and the admin wants to define the dates every time the definition runs in Flows.
The admin defines the definition as:
- Name: Calculate Purchase Credit and Bonus
- API Name: Calculate_Purchase_Credit_and_Bonus
- Process Type: Standard
Here's how the admin defined each node in the definition along with the input variables. The sequence that the nodes are created in is also specified.
1. Select Data Sources
The admin selects two data source objects and the required fields from each object.
| Node Type | Node Name | Object | Node Configuration |
|---|---|---|---|
| Data Source | Order | Order | Selected fields:
|
| Data Source | User | User | Selected fields:
|
The admin requires only these two objects as data sources and not the Account object because the AccountId is a related field of the Order object.
2. Create Input Variables
To filter Order records that were placed and fulfilled during a particular year, two filter variables are required.
| Input Variable Name | Type |
|---|---|
| OrderEffectiveDate | Date |
| OrderEndDate | Date |
The values for both input variables aren't defined because the admin wants to define the values based on the year when the definition is run.
3. Filter Orders
Next, the admin creates a Filter node that filters out Order records with effective dates that were closed during the year.
| Node Type | Node Name | Source Node | Node Configuration |
|---|---|---|---|
| Filter | Filter Orders | Order |
|
4. Join Order and Contact
The admin joins the two tables to use only the data for the filtered orders and the associated users. The admin selects the Join Type as Inner to ensure that only the records for salespeople associated with the orders are included in the joined dataset.
| Node Type | Node Name | Source Nodes | Node Configuration |
|---|---|---|---|
| Join | Join Filtered Orders and Users |
|
|
5. Group by Account and Aggregate Total Amount
The admin creates a node that groups the orders by account and calculates the sum of the order amounts of all the filtered orders associated with each account.
| Node Type | Node Name | Source Node | Node Configuration |
|---|---|---|---|
| Group and Aggregate | Group by Account and Sum Total Amount | Join Filtered Orders and Users |
|
6. Group by User and Aggregate Total Amount
The admin creates another similar node. This node groups the orders by the associated user and calculates the sum of the order amounts of all the filtered orders associated with each user.
| Node Type | Node Name | Source Node | Node Configuration |
|---|---|---|---|
| Group and Aggregate | Group by User and Sum Total Amount | Join Filtered Orders and Users |
|
7. Calculate Purchase Credit for Accounts
To calculate the purchase credit amount, this formula uses the sum calculated in the Group by Account and Sum Total Amount node.
| Node Type | Node Name | Source Node | Node Configuration |
|---|---|---|---|
| Formula | Purchase Credit Amount | Group by Account and Sum Total Amount |
|
8. Calculate Bonus for Users
To calculate the bonus amount this formula uses the sum calculated in the Group by User and Sum Total Amount node.
| Node Type | Node Name | Source Node | Node Configuration |
|---|---|---|---|
| Formula | Bonus Amount | Group by User and Sum Total Amount |
|
9. Write Back Purchase Credit for Accounts
In this step, a Writeback Object node is created to write back the Purchase Credit Amount to the Purchase Credit custom field on the Account object.
| Node Type | Node Name | Source Node | Node Configuration |
|---|---|---|---|
| Writeback Objects | Update Purchase Credit for Accounts | Purchase Credit Amount |
|
10. Write Back Salesperson Bonus Amount
In this last step, a Writeback Object node is created to write back the bonus amount and the other employee details to the Salesperson Bonus custom object.
| Node Type | Node Name | Source Node | Node Configuration |
|---|---|---|---|
| Writeback Objects | Update Bonus for Salespeople | Bonus Amount |
|
