---
schema_version: "1"
id: 3e2560e101754a3968ba6abb899d5965c83150d8fb3bae55dec984a55a17d56f
title: Set Up Automatic Meal Calculation
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/aslm_tmsht_set_up_automatic_meal_calculation.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.aslm_tmsht_set_up_automatic_meal_calculation.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 15d4496c1dccf8b0f493890144d62678c9637c183e75da32f03a58d77e1289ed
description: 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.
products:
  - Industry Solutions
  - Cross Cloud
release: "264"
---
# 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

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: All editions of Field Service Plus for Energy and Utilities, and all editions of Asset Service Lifecycle Management</td></tr></tbody></table>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d24919e60">User
              Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e60 ">To access flow templates</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e60 ">Labor Cost Optimization Admin</td>

          </tr>
        </tbody>
      </table>

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](https://help.salesforce.com/s/articleView?id=ind.context_service_turn_on_context_service.htm&type=5&language=en_US) .

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.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:33.33333333333333%">
          <col style="width:66.66666666666666%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d24919e110">BRE Expression Set Name</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d24919e113">BRE Expression Set Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="BRE Expression Set Name" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e110 ">Timesheet Meals And Gifts Computation Rule</td>

            <td data-label="BRE Expression Set Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e113 ">
              <p>Computes meals and gifts for a timesheet using the standard context definition <code>TimesheetMealsAndGiftsComputation</code>.
              </p>
              <p style="margin-bottom:0;">Creates Supplemental Compensation records based on the approved Time Sheet Entry Items in a Timesheet.
              </p>
            </td>

          </tr>
        </tbody>
      </table>

The service resource cost rule record is used in the Process Approved Timesheet ﬂow 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.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:25%">
          <col style="width:25%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d24919e158">Flow Template Name</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d24919e161">Usage</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d24919e164">Flow Template Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Flow Template Name" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e158 ">Process Approved TimeSheet</td>

            <td data-label="Usage" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e161 ">Desktop</td>

            <td data-label="Flow Template Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e164 ">Sends an email to the technician of the approved timesheet and
              calls a flow to compute
              the meals and gifts earned through the timesheet.</td>

          </tr>
          <tr class="">
            <td data-label="Flow Template Name" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e158 ">Compute TimeSheet Meals and Gifts</td>

            <td data-label="Usage" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e161 ">Desktop and Mobile</td>

            <td data-label="Flow Template Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e164 ">
              <p>Queries all Service Resource Cost Rule objects of type <strong>Meal Computation</strong>. Rules
                can have a BRE Expression (ServiceResourceCostRule.Rule) and
                Apex Class (ServiceResourceCostRule.ApexClass) or both.
              </p>
              <p style="margin-bottom:0;">Calls an Invocable Action (<strong>Invoke Rule</strong>) to execute the rules. The rules store
                the logic for calculating supplemental compensation (meals and gifts).
              </p>
            </td>

          </tr>
        </tbody>
      </table> <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col style="width:25%">
          <col style="width:25%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d24919e225">Invocable Action Name</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d24919e228">Related Flow</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d24919e231">Invocable Action Description</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Invocable Action Name" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e225 ">Invoke Rule</td>

            <td data-label="Related Flow" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e228 ">Compute Time Sheet Meals and Gifts Flow</td>

            <td data-label="Invocable Action Description" class="slds-cell-wrap" style="vertical-align:top;" headers="d24919e231 ">
              <p>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 <code>Upsert
                    Record</code> element, it creates sObject records. </p>
              <p style="margin-bottom:0;">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 <code>UpsertRecord</code>
                element only appears if you select <code>Timesheet</code> for the <strong>UsageType</strong> value while
                creating an expression set.

              </p>
            </td>

          </tr>

        </tbody>
      </table>

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 ﬂow.
    
    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.

#### See Also

- [Context Service](https://help.salesforce.com/s/articleView?id=ind.context_service.htm&language=en_US)
- [Expression Sets](https://help.salesforce.com/s/articleView?id=ind.expression_sets.htm&type=5&language=en_US)