Set Up Automatic Meal Calculation

Set up the flows and Business Rules Engine components that you can use to automatically calculate the meals and supplementary compensation earned by mobile workers for approved time sheets.

Required Editions

Available in: Lightning Experience
Available in: All editions of Field Service Plus for Energy and Utilities, and all editions of Asset Service Lifecycle Management
User Permissions Needed
To access flow templates Labor Cost Optimization Admin

Before you begin: To automatically calculate meal coupons and other supplemental compensation for approved timesheets, you must enable Context Service. See Turn On Context Service .

Create an expression set from the Timesheet Meals and Gifts Computation Rule template. Create a Service Resource Cost Rule record. On the Service Resource Cost Rule page, set Rule as an optional field.

Use the Service Resource Cost Rule record to define rules to validate time sheets. You can use either an expression set or an Apex class to validate the time sheet. Alternatively, you can build an Apex class to provide data to the expression set, which then validates the time sheet. To do this, enter the API names of the Apex class and the expression set in the Service Resource Cost Rule record.

BRE Expression Set Name BRE Expression Set Description
Timesheet Meals And Gifts Computation Rule

Computes meals and gifts for a timesheet using the standard context definition TimesheetMealsAndGiftsComputation.

Creates Supplemental Compensation records based on the approved Time Sheet Entry Items in a Timesheet.

The service resource cost rule record is used in the Process Approved Timesheet flow to automatically calculate meals for a time sheet. To use the Service Resource Cost Rule record in the Process Timesheet flow, set the Type to Meal Calculations.

Flow Template Name Usage Flow Template Description
Process Approved TimeSheet Desktop Sends an email to the technician of the approved timesheet and calls a flow to compute the meals and gifts earned through the timesheet.
Compute TimeSheet Meals and Gifts Desktop and Mobile

Queries all Service Resource Cost Rule objects of type Meal Computation. Rules can have a BRE Expression (ServiceResourceCostRule.Rule) and Apex Class (ServiceResourceCostRule.ApexClass) or both.

Calls an Invocable Action (Invoke Rule) to execute the rules. The rules store the logic for calculating supplemental compensation (meals and gifts).

Invocable Action Name Related Flow Invocable Action Description
Invoke Rule Compute Time Sheet Meals and Gifts Flow

This invocable action runs Service Resource Cost Rules asynchronously. First, an Apex class is executed as the data provider for the expression set. Then, the response from the Apex class is used to define the context. Next, the context is passed to the expression set for execution. Finally, based on the Upsert Record element, it creates sObject records.

Upsert Record is a custom element for Business Rules Engine (BRE). It lets users create sObject records. If you use this invocable action, records are created. However, records aren't created if the expression set is directly executed. The UpsertRecord element only appears if you select Timesheet for the UsageType value while creating an expression set.

  1. Clone the Flow Builder templates available with Timesheets and Labor Cost Optimization. You must create at least one flow from each of the templates listed earlier.
    1. From Setup, find and select Flows under Process Automation.
    2. Click the flow template that you want to clone. For example, click Approve Time Sheets.
    3. On the header of the flow builder, click Save As and enter a flow label and a flow API name.
    4. Save your changes.
    5. Activate the flow.
  2. Create an expression set from the Timesheet Meals and Gift Computation Rule template
    The Timesheet Meals and Gift Computation Rule expression set is used in the Process Approved Timesheet flow.
    1. From the App Launcher, find and select Expression Set Templates.
    2. Click Timesheet Meals And Gifts Computation Rule .
    3. In Expression Set Properties, in Rank, enter 1.

      When more than one enabled version matches an expression set call, and the datetime periods overlap, the version with the highest rank is chosen. For example, if two enabled versions have rank values set to 1 and 2, the version with rank 2 is chosen.

    4. Save and activate the expression set.
  3. To use either Expression Sets or Apex Classes to validate time sheet records, set the Rule field in the service resource cost rule page as an optional field.
    1. From the object management settings for Service Resource Cost Rule, go to Page Layout.
    2. To open the properties of the Rule field: In the Service Resource Cost Rule Detail section, for the Rule field, click Properties .
    3. To set Rule as an optional field, deselect Required .
    4. Save your changes.
  4. Create a service resource cost rule.
    1. From the App Launcher, find and select Service Resource Cost Rule.
    2. Click New.
    3. Enter a name. For example, Compute Meals & Gifts.
    4. In Rule, enter the API name of the expression set or the Apex class that you want to use to validate the time sheet. For example, TimesheetMealsAndGiftsComputationRule.
    5. Select a labor union.
    6. Activate the rule.
    7. For Type, select Meal Calculations, and save your changes.