Skip to content

navipartner/pos-data-source-extension-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

POS Data Source Extension Example

An example Per-Tenant Extension for Business Central that demonstrates how to extend the NP Retail POS data sources with custom fields.

The POS frontend displays data from three built-in data sources. Partners can add custom fields to any of them using integration events, making the fields available across the POS UI — in grids, footer, product panel, and more.

Data Sources

Data Source Constant Available in UI areas
BUILTIN_SALELINE POSDataSource_BuiltInSaleLine() Sale Lines grid, Footer, Product Panel
BUILTIN_SALE POSDataSource_BuiltInSale() Sale grid, Sale Totals, Footer, Product Panel
BUILTIN_PAYMENTLINE POSDataSource_BuiltInPaymentLine() Payment grid, Payment Totals, Footer, Product Panel

Note: The Totals values (e.g. AmountExclVAT, TotalAmount, SaleAmount, PaidAmount) are hardcoded in core and are not extensible via this mechanism.

How It Works

Each extension subscribes to three integration events on the NPR POS Data Management codeunit:

  1. OnDiscoverDataSourceExtensions — Register your extension name for a data source.
  2. OnGetDataSourceExtension — Define your custom columns (name, caption, data type, visibility).
  3. OnDataSourceExtensionReadData — Provide the actual field values for each row.

Once deployed, the new fields automatically appear in the POS View Profile configuration, where the user can toggle visibility, rename captions, and set alignment.

Examples

This app contains three example codeunits, one for each data source:

Sale Line — Vendor Item No.

Folder: src/SaleLineExtension/

Adds a "Vendor Item No." column to the sale line grid by looking up the vendor item number from the Item table.

Sale — Customer Phone No.

Folder: src/SaleExtension/

Adds a "Customer Phone No." field to the sale data source by looking up the phone number from the Customer table. Available in the Sale grid, Sale Totals area, Footer, and Product Panel.

Payment Line — Payment Method Description

Folder: src/PaymentLineExtension/

Adds a "Payment Method Desc." column to the payment line data source by looking up the description from the NPR POS Payment Method table.

Minimal Example

Below is the minimal code needed to add a custom field to the sale line grid:

codeunit 50100 "PTE Vendor Item No. DS Ext."
{
    Access = Internal;

    local procedure ExtensionName(): Text
    begin
        exit('VendorItemNo');
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"NPR POS Data Management",
        'OnDiscoverDataSourceExtensions', '', false, false)]
    local procedure OnDiscover(DataSourceName: Text; Extensions: List of [Text])
    var
        POSDataMgt: Codeunit "NPR POS Data Management";
    begin
        if DataSourceName <> POSDataMgt.POSDataSource_BuiltInSaleLine() then
            exit;
        Extensions.Add(ExtensionName());
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"NPR POS Data Management",
        'OnGetDataSourceExtension', '', false, false)]
    local procedure OnGetExtension(DataSourceName: Text; ExtensionName: Text;
        var DataSource: Codeunit "NPR Data Source"; var Handled: Boolean;
        Setup: Codeunit "NPR POS Setup")
    var
        POSDataMgt: Codeunit "NPR POS Data Management";
        DataType: Enum "NPR Data Type";
    begin
        if (DataSourceName <> POSDataMgt.POSDataSource_BuiltInSaleLine())
            or (ExtensionName <> ExtensionName())
        then
            exit;

        Handled := true;
        DataSource.AddColumn(ExtensionName(), 'Vendor Item No.', DataType::String, false);
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"NPR POS Data Management",
        'OnDataSourceExtensionReadData', '', false, false)]
    local procedure OnReadData(DataSourceName: Text; ExtensionName: Text;
        var RecRef: RecordRef; DataRow: Codeunit "NPR Data Row";
        POSSession: Codeunit "NPR POS Session";
        FrontEnd: Codeunit "NPR POS Front End Management"; var Handled: Boolean)
    var
        SaleLinePOS: Record "NPR POS Sale Line";
        Item: Record Item;
        POSDataMgt: Codeunit "NPR POS Data Management";
        VendorItemNo: Text;
    begin
        if (DataSourceName <> POSDataMgt.POSDataSource_BuiltInSaleLine())
            or (ExtensionName <> ExtensionName())
        then
            exit;

        Handled := true;

        RecRef.SetTable(SaleLinePOS);
        if (SaleLinePOS."Line Type" = SaleLinePOS."Line Type"::Item)
            and Item.Get(SaleLinePOS."No.")
        then
            VendorItemNo := Item."Vendor Item No.";

        DataRow.Fields().Add(ExtensionName(), VendorItemNo);
    end;
}

Setup

After deploying the extension:

  1. Login into the POS
  2. Open POS Editor
  3. Go to the Sale Lines / Totals / Footer / Product Panel tab
  4. Your new fields will appear in the field selection of extended data source
  5. Enable them (Optionally: configure captions and alignment if needed)

Prerequisites

  • NP Retail installed on your Business Central environment.
  • The app.json dependency version for NP Retail must match the version installed on your target environment.

About

Extension that demonstrates how to add custom fields to the NP Retail POS sale line, sale, and payment line data sources

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages