---
title: "Advanced Technical Example : Calling Shop Floor Business Central Methods in AL directly"
app: "Shop Floor Insight"
section: "Set up"
last_updated: "2026-10-27"
url: "https://insight-works.com/kb/shop-floor-insight/advanced-technical-example-calling-shop-floor-business-central-methods-in-al-directly/"
---

# Advanced Technical Example : Calling Shop Floor Business Central Methods in AL directly

An AL extension can call Shop Floor Insight’s business methods directly, passing employee, configuration, time card, and operation records.

There are many approaches to this, this article intends to help document one approach.

The examples below do not construct a `MENUITEM` request or run **SFI Action Handler** to simulate a web service call.

Some business methods accept a temporary **SFI Action Response Buffer**. This collects instructions generated during processing, including workflow interactions. It does not replace the employee, configuration, or time card records passed to those methods.  The Action Response Buffer record is intended to be used with the Shop Floor Insight scanning interface.

## Example 1: Sign In Using an Employee Barcode

Use **SFI Barcode Mgmt** to decode the employee barcode, then call **SFI Employee Action Handlers** → `HandleEmployeeClockScan`.

`HandleEmployeeClockScan` authenticates the badge, runs the authorization processing, obtains or creates the applicable time card, updates the employee’s in/out state, and invokes the after-authorization processing.

For an ordinary sign-in, use **Force In** rather than **Auto**. Automatic direction is appropriate when intentionally implementing an in/out clock, rather than a sign-in action.

```
procedure SignInExample(
    var Employee: Record "SFI Employee";
    var TimeCard: Record "SFI Time Card Header";
    var ClientConfig: Record "SFI Client Configuration")
var
    Barcode: Record "SFI Barcode Entry";
    BarcodeManagement: Codeunit "SFI Barcode Mgmt";
    EmployeeHandlers: Codeunit "SFI Employee Action Handlers";
    ConfigManagement: Codeunit "SFI Config";
    Direction: Option Auto,"Force In","Force Out";
    OptionalAuthData: BigText;
    BarcodeType: Char;
    BarcodePayload: Text;
begin
    Clear(Employee);
    Clear(TimeCard);
    Clear(ClientConfig);

    BarcodeManagement.LookupAndParseBarcodeRecord(
        '/R00000001%',
        BarcodeType,
        BarcodePayload,
        Barcode);

    if Barcode.Type <> Barcode.Type::Employee then
        Error('The scanned barcode must identify an employee.');

    if Barcode."Context Is Break" then
        Error('Use the employee sign-in badge, not a break badge.');

    // This example deliberately uses a specific configuration.
    ClientConfig."No." := 'CFG000001';
    ConfigManagement.VerifyConfig(
        '', '192.168.123.45', ClientConfig);

    Direction := Direction::"Force In";

    if not EmployeeHandlers.HandleEmployeeClockScan(
        Barcode,
        ClientConfig."No.",
        Direction,
        OptionalAuthData,
        Employee,
        TimeCard)
    then
        Error('The employee badge could not be authenticated.');

    TimeCard.TestField("No.");

    if Direction <> Direction::"Force In" then
        Error('The employee was not clocked in.');

    // Re-read the resulting records rather than assuming their values.
    TimeCard.Get(TimeCard."No.");
    TimeCard.TestField(Open, true);
    ClientConfig.Get(TimeCard."TCM Client Config. No.");
end;
```

Use the returned records for subsequent operations:

- `Employee."No."` supplies the employee context.
- `TimeCard."No."` identifies the applicable time card.
- `ClientConfig."No."` identifies the effective configuration used by this example.

For the remaining examples, these values are represented by `EMP001`, `TC000123`, and `CFG000001`.

No additional call to `Login` or `getaTimeCard` is required simply to create the card: the authorization path invoked by `HandleEmployeeClockScan` already obtains it.

This example uses a fixed configuration. If your interface resolves configuration by employee or terminal address, implement that policy explicitly using **SFI Config**. Calling the employee handler directly does not execute the outer interface’s configuration-switching logic.

Clearing the input time card makes this an individual sign-in example. Joining an existing group card is a different scenario and requires supplying the intended group context.

## Example 3: Start Time on a Selected Dispatch Row

Use **SFI Time Action Handlers** → `ClockOnWithBarcodeData` when the application has explicitly selected an operation and intends to start time.

Despite its name, this method does not require a scanned barcode string. It accepts an **SFI Barcode Entry** record containing the operation context.

For a selected dispatch row, populate that record with:

- Type: `Routing`
- Context Key 1: production order number
- Context Key 2: production order line number
- Context Key 3: operation number
- Context Calc Type: run time or setup time

```
procedure ClockOnDispatchExample(
    var NewTimeCardLine: Record "SFI Time Card Line";
    var Responses: Record "SFI Action Response Buffer" temporary)
var
    Employee: Record "SFI Employee";
    TimeCard: Record "SFI Time Card Header";
    ClientConfig: Record "SFI Client Configuration";
    OperationContext: Record "SFI Barcode Entry" temporary;
    TimeHandlers: Codeunit "SFI Time Action Handlers";
    SfiDateTime: Codeunit "SFI Current Datetime";
begin
    Employee.Get('EMP001');
    TimeCard.Get('TC000123');
    TimeCard.TestField(Open, true);
    TimeCard.TestField("Employee No.", Employee."No.");

    ClientConfig.Get(TimeCard."TCM Client Config. No.");

    // Update the current activity timestamp before processing
    // any automatic clock-off of an existing entry.
    TimeCard.Validate(
        "Logout Time", SfiDateTime.GetCurrentDateTime());
    TimeCard.Modify(false);

    OperationContext.Type := OperationContext.Type::Routing;
    OperationContext."Context Key 1" := 'RPO00123';
    OperationContext."Context Key 2" := 10000;
    OperationContext."Context Key 3" := '20';
    OperationContext."Context Calc Type" :=
        OperationContext."Context Calc Type"::Runtime;

    Responses.Reset();
    Responses.DeleteAll();
    Clear(NewTimeCardLine);

    TimeHandlers.ClockOnWithBarcodeData(
        Responses,
        ClientConfig,
        Employee,
        TimeCard,
        OperationContext,
        NewTimeCardLine);
end;
```

For an actual dispatch selection, use its production order, production order line, and operation values instead of the literals.

`ClockOnWithBarcodeData` applies the standard line creation/defaulting logic and starts the applicable clock-on workflows. Depending on the configuration, it can also close a previous entry.

This is an explicit start method. It does not perform the same matching-and-toggle decision as `HandleTimeScan`.

The final parameter is an in/out record used by the method. For this single-operation start example, it is cleared before the call and receives the resulting line. Do not pass an unrelated filtered record into that parameter.

Review any returned workflow instructions and re-read the resulting time card records before reporting completion.

For setup time, set `Context Calc Type` to `Setuptime`.

## Example 4: Start and Stop Time Using a Routing Barcode

Use **SFI Time Action Handlers** → `HandleTimeScan` when the intended behavior is “process this scan” rather than “start this operation.”

First decode the scanned barcode, then pass the resulting barcode record together with the actual employee, configuration, and time card records.

```
procedure ScanRoutingExample(
    var Responses: Record "SFI Action Response Buffer" temporary)
var
    Barcode: Record "SFI Barcode Entry";
    Employee: Record "SFI Employee";
    TimeCard: Record "SFI Time Card Header";
    ClientConfig: Record "SFI Client Configuration";
    BarcodeManagement: Codeunit "SFI Barcode Mgmt";
    TimeHandlers: Codeunit "SFI Time Action Handlers";
    BarcodeType: Char;
    BarcodePayload: Text;
begin
    Employee.Get('EMP001');
    TimeCard.Get('TC000123');
    TimeCard.TestField(Open, true);
    TimeCard.TestField("Employee No.", Employee."No.");

    ClientConfig.Get(TimeCard."TCM Client Config. No.");

    BarcodeManagement.LookupAndParseBarcodeRecord(
        '/O00000001%',
        BarcodeType,
        BarcodePayload,
        Barcode);

    if Barcode.Type <> Barcode.Type::Routing then
        Error('The scanned barcode must identify a production operation.');

    Responses.Reset();
    Responses.DeleteAll();

    TimeHandlers.HandleTimeScan(
        Responses,
        ClientConfig,
        Employee,
        TimeCard,
        Barcode);
end;
```

`HandleTimeScan` performs the higher-level scan decision:

- Finds a matching open entry.
- Updates the time card’s activity timestamp.
- Starts a new entry when no matching open entry exists.
- Clocks off a matching entry in the applicable automatic time entry modes.
- Selects the matching entry rather than automatically clocking it off in Manual mode.

Use `/N00000001%` for the example setup barcode.

This example intentionally has no selected time card line. Selection-sensitive behavior, including preferred matching, grace time, and activity changes, requires supplying that selection context. The method’s response buffer also provides the optional selection context used by those behaviors.

Do not repeat the scan merely because no AL error occurred or because the outcome is unclear. Inspect the resulting records and any workflow instructions first.

## Choosing Between ClockOnWithBarcodeData and HandleTimeScan

| Requirement | Appropriate method |
| --- | --- |
| The operator selected an operation and pressed Start | `ClockOnWithBarcodeData` |
| The operator scanned a routing barcode and expects the normal scan behavior | `HandleTimeScan` |
| The application already knows the exact time card line to stop | `ClockOffLine` |

`HandleTimeScan` is the higher-level start/stop scan processor. `ClockOnWithBarcodeData` is the explicit clock-on operation used within that processing.

## Example 5: Stop a Specific Time Card Line

Use **SFI Time Action Handlers** → `ClockOffLine` when the application already knows which time card line to stop.

This retains the before- and after-clock-off workflow processing. Calling the lower-level line clock calculation directly would omit that surrounding workflow behavior.

```
procedure ClockOffLineExample(
    var Responses: Record "SFI Action Response Buffer" temporary)
var
    TimeCard: Record "SFI Time Card Header";
    TimeCardLine: Record "SFI Time Card Line";
    TimeHandlers: Codeunit "SFI Time Action Handlers";
    SfiDateTime: Codeunit "SFI Current Datetime";
begin
    TimeCard.Get('TC000123');
    TimeCard.TestField(Open, true);

    TimeCardLine.Get(TimeCard."No.", 10000);

    if TimeCardLine."Entry Clock Off Time" <> 0DT then
        Error('The selected time card line is already clocked off.');

    TimeCard.Validate(
        "Logout Time", SfiDateTime.GetCurrentDateTime());
    TimeCard.Modify(false);

    Responses.Reset();
    Responses.DeleteAll();

    TimeHandlers.ClockOffLine(
        Responses,
        TimeCard,
        TimeCardLine);
end;
```

A before-clock-off workflow can stop the operation. Re-read the selected line and process the returned instructions before reporting that clock-off completed.

`ClockOffLine` can also participate in configured time-splitting behavior. If the requirement is specifically to stop one member of a split set while keeping the other entries running, evaluate the public `ClockOffSingleLine` method instead.

## Response Buffers and Direct AL Calls

These examples remove the simulated web service request. They do not remove the response/workflow contract required by the business methods.

Employee sign-in through `HandleEmployeeClockScan` returns native employee and time card records and an updated direction. It does not require parsing a `RESP.SIGNIN` JSON payload.

The time action methods still accept a temporary response buffer because they can generate selection, refresh, message, and workflow instructions. Your extension must handle the relevant instructions rather than treating the buffer as disposable diagnostic output.

Calling these methods directly also means the outer action handler’s logging and generic action hooks are not invoked. The selected business methods retain their own authorization, clocking, and workflow processing.
