Clock in and out exception forms

Some clients need extra information when a clock in or clock out falls outside the rules. For example, they may ask why the worker is away from the site, whether a manager authorised it and who that was. The Clock app supports this through action forms: a small form that opens straight after the worker taps Start shift or End shift. Each field on the form, and the form itself, can be shown only when the clock event breaks a rule.

How it works

  1. The worker taps Start shift or End shift. At that moment the app records the device location and the time.
  2. The shift is started or ended and the Geo Tag is written, as usual.
  3. The app works out a set of facts about this clock event, called the clock context. Examples are the distance from the site and how many minutes the event is from the scheduled time.
  4. The configured action form opens if its isVisble condition matches. Inside the form, each field's showIf, required and disabled conditions can test the clock context as well as other answers on the form.
  5. The worker's answers are saved to the Shift record.

The clock context is only available to these conditions. It is never stored on the Shift.

Clock context keys

Reference these keys as $clock.<key> in the field of any condition selector on an action form.

Key Type Meaning
$clock.action text startShift or endShift.
$clock.isAdhoc boolean true when the shift has no scheduled start, meaning the worker started an ad-hoc shift.
$clock.distanceMeters number Straight-line distance in metres between the device and the shift's site location. Blank when either location is unknown.
$clock.locationUnavailable boolean true when the device gave no location, for example because permission was denied or there was no GPS fix.
$clock.accuracyMeters number Accuracy of the device location as reported by the device, in metres.
$clock.minutesVariance number Minutes between the tap and the scheduled time. For clock in this is the scheduled start; for clock out it is the scheduled end. A positive value means late, a negative value means early. Blank for ad-hoc shifts.
$clock.minutesVarianceAbs number The same value with the sign removed. Use it to mean "more than N minutes either side".

The site location comes from the shift schedulable's shiftLatFieldPath and shiftLonFieldPath (in the sample, b3s__Work_Site__r.b3s__Location__Latitude__s and ...Longitude__s). The scheduled times come from startFieldPath and endFieldPath.

Thresholds live in your conditions. There is no separate radius or minutes setting. Write the limit straight into the selector, for example greaterthan 200 metres or greaterthan 120 minutes. A blank value never matches greaterthan or lessthan, so a missing site location does not count as being away from the site. Use $clock.locationUnavailable if a missing device location should count as an exception.

Common selectors:

Rule Selector
Away from site by more than 200 m { "field": "$clock.distanceMeters", "operator": "greaterthan", "value": 200 }
More than 15 minutes early { "field": "$clock.minutesVariance", "operator": "lessthan", "value": -15 }
More than 10 minutes late (or overtime on clock out) { "field": "$clock.minutesVariance", "operator": "greaterthan", "value": 10 }
Outside plus or minus 120 minutes { "field": "$clock.minutesVarianceAbs", "operator": "greaterthan", "value": 120 }
Ad-hoc shift { "field": "$clock.isAdhoc", "operator": "equals", "value": true }
No device location { "field": "$clock.locationUnavailable", "operator": "equals", "value": true }

Combine selectors with "allOrSome": "some" (any rule) or "all" (every rule).

Configuring the action forms

Action forms live on the Clock app's shift schedulable, in schedulables.shift.actionForms, inside the b3s__Component_Configuration__mdt record for the Clock app.

Setting Type Meaning
startShift / endShift object The form shown after clock in or clock out. Leave one out to show no form for that action.
isVisble boolean or condition When the form opens. Leave it out to open the form every time. The spelling isVisble is intentional and must be used as written.
mandatory boolean or condition When it matches, the worker cannot close the form without saving: the Cancel and close buttons are hidden, and Escape, the Android back gesture and tapping outside the form are ignored. Defaults to false.
recordFormFields array The fields on the form. Every entry follows the RecordForm field reference. Use showIf, required and disabled with $clock selectors to make fields conditional.

The form saves only the values the worker entered. It never re-saves the shift's clock times.

Packaged Shift fields

The package includes generic fields so the answers can be reported on without any customisation. You can use your own fields instead by naming them in recordFormFields.

Field Type Purpose
b3s__Clock_In_Exception_Reason__c / b3s__Clock_Out_Exception_Reason__c Picklist (unrestricted) Why the event broke the rules. Ships with sample values; add or replace values to suit the client.
b3s__Clock_In_Authorised__c / b3s__Clock_Out_Authorised__c Checkbox The worker confirms the exception was authorised in advance.
b3s__Clock_In_Authorised_By__c / b3s__Clock_Out_Authorised_By__c Text (255) Who authorised it.
b3s__Clock_In_Exception_Comments__c / b3s__Clock_Out_Exception_Comments__c Long text Free-text comments.

The WFM Admin permission set grants edit access to these fields. Portal and kiosk workers need no extra permissions.

Sample configuration

The sample Clock configuration (WFM_Clock_In_Out_Config) uses one exception rule: more than 200 m from the site, more than 120 minutes either side of the scheduled time, or an ad-hoc shift.

"actionForms": {
    "startShift": {
        "isVisble": { "condition": { "allOrSome": "some", "selectors": [
            { "field": "$clock.distanceMeters", "operator": "greaterthan", "value": 200 },
            { "field": "$clock.minutesVarianceAbs", "operator": "greaterthan", "value": 120 },
            { "field": "$clock.isAdhoc", "operator": "equals", "value": true }
        ] } },
        "mandatory": true,
        "recordFormFields": [
            { "field": "b3s__Clock_In_Exception_Reason__c", "type": "field-select", "required": true },
            { "field": "b3s__Clock_In_Authorised__c", "type": "field-checkbox" },
            { "field": "b3s__Clock_In_Authorised_By__c", "type": "field-text", "required": true,
              "showIf": { "condition": { "allOrSome": "all", "selectors": [
                  { "field": "b3s__Clock_In_Authorised__c", "operator": "equals", "value": true }
              ] } } },
            { "field": "b3s__Clock_In_Exception_Comments__c", "type": "field-text-area" }
        ]
    },
    "endShift": {
        "mandatory": { "condition": { "allOrSome": "some", "selectors": [
            { "field": "$clock.distanceMeters", "operator": "greaterthan", "value": 200 },
            { "field": "$clock.minutesVarianceAbs", "operator": "greaterthan", "value": 120 },
            { "field": "$clock.isAdhoc", "operator": "equals", "value": true }
        ] } },
        "recordFormFields": [
            { "field": "b3s__Clock_Out_Exception_Reason__c", "type": "field-select", "required": true,
              "showIf": { "condition": { "allOrSome": "some", "selectors": [
                  { "field": "$clock.distanceMeters", "operator": "greaterthan", "value": 200 },
                  { "field": "$clock.minutesVarianceAbs", "operator": "greaterthan", "value": 120 },
                  { "field": "$clock.isAdhoc", "operator": "equals", "value": true }
              ] } } },
            { "field": "b3s__Comments__c", "type": "field-text-area" }
        ]
    }
}

The full sample WFM_Clock_In_Out_Config record also adds the clock-out Authorised, Authorised By and Comments fields. It shows every exception field only when the rule matches.

To ask different questions for location and time exceptions, give each field its own showIf. For example, show a location reason when $clock.distanceMeters is over the limit and a separate time reason when $clock.minutesVarianceAbs is over the limit.

Good to know