Table of Contents

Event Subscriptions

There are several events published that developers can subscribe to.

Codeunit 20020851 "ITI ICI Management"

  • OnBeforeInsertAvailabilityLine(var ITIICIAvailability: Record "ITI ICI Availability"; JsonObj: JsonObject)

    This event is triggered when a response with availability data has been received. It occurs just before inserting the availability entry. It can be used to copy any additional fields from the json response.

    The fields are placed in the json objects with field names from the 20020852 ITI ICI Availability WS page. Spaces are replaced by underscores and dots are removed, for example Item No. becomes Item_No.

  • OnBeforeInsertCustomerBalanceLine(var ITIICICustomerBalance: Record "ITI ICI Customer Balance"; JsonObj: JsonObject)

    This event is triggered when a response with customer data has been received. It occurs just before inserting the customer balance entry. It can be used to copy any additional fields from the json response.

    The fields are placed in the json objects with field names from the 20020852 ITI ICI Availability WS page. Spaces replaced by underscores and dots are removed.

  • OnBeforeInsertCustomerBalanceDetailLine(var ITIICICustLEntryBuffer: Record "ITI ICI Cust. L. Entry Buffer"; JsonObj: JsonObject)

    This event is triggered when a response with customer details data has been received. It occurs just before inserting the temporary customer ledger entry. It can be used to copy any additional fields from the json response.

    The fields are placed in the json objects with field names from the 20020858 ITI ICI Cust. Ledger Entry WS page. Spaces replaced by underscores and dots are removed, for example Document No. becomes Document_No.

  • OnBeforeDeleteEndpointICIAvailability(var ITIICIAvailability: Record "ITI ICI Availability"; ITIICIEndpoint: Record "ITI ICI Endpoint"; var IsHandled: Boolean)

    This event is triggered before sending a request to the intercompany partner to update availability or customer balance information. It can be used to prevent deleting old records.

Codeunit 20020852 "ITI ICI Sender Mgt."

  • OnCreateAvailabilityLine(var Item: Record Item; var ITIICIAvailability: Record "ITI ICI Availability" temporary)

    This event is triggered when a request for availability data is received and a response is being built. It occurs for each of the item, variant and location combination that matches filters (items and variants) and setup (locations).

    It can be used to fill any additional fields in the buffer. The item is passed as VAR to keep location and variant filters, so CalcFields can be called. The fields should be filled with a += operator instead of :=, to comply also with the sum of all locations scenario.

  • OnCreateCustomerBalanceLine(Customer: Record Customer; var ITIICICustomerBalance: Record "ITI ICI Customer Balance" temporary)

    This event is triggered when a request for customer data is received and a response is being built. It occurs for each customer that matches the filter.

    It can be used to fill any additional fields in the buffer.

Example

Table Extension

The new fields need to be added to the extended table.

tableextension 50149 "ITIICIAvailability" extends "ITI ICI Availability"
{
    fields
    {
        field(50149; "Description"; Text[100])
        {
        }
        field(50148; "Sales (Qty.)"; Decimal)
        {
        }
    }
}

Page Extensions

The new fields need to be added to the web service page. If they should be visible on the availability overview, they can also be added to the ITI ICI Availability Overview page. On the ITI ICI Availability WS page, it is recommended not to use spaces or dots in field names, so the same will be presented in the json object.

pageextension 50148 MyExtension2 extends "ITI ICI Availability WS"
{
    layout
    {
        addlast(Group)
        {
            field(Description; "Description")
            {
                ApplicationArea = All;
            }
            field(SalesQty; "Sales (Qty.)")
            {
                ApplicationArea = All;
            }
        }
    }
}


pageextension 50149 MyExtension extends "ITI ICI Availability Overview"
{
    layout
    {
        addlast(Group)
        {
            field(Description; "Description")
            {
                ApplicationArea = All;
            }
            field(SalesQty; "Sales (Qty.)")
            {
                ApplicationArea = All;
            }
        }
    }
}

Adding Data to the Buffer

Data needs to be calculated and added to the buffer.

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"ITI ICI Sender Mgt.", 'OnCreateAvailabilityLine', '', false, false)]
    local procedure MyProcedure(var Item: Record Item; var ITIICIAvailability: Record "ITI ICI Availability")
    begin
        Item.CalcFields("Sales (Qty.)");
        ITIICIAvailability."Sales (Qty.)" += Item."Sales (Qty.)";
        ITIICIAvailability.Description := Item.Description;
    end;

Reading Data from json

The values need to be retrieved from the json objects, read as correct types and assigned to desired fields.

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"ITI ICI Management", 'OnBeforeInsertAvailabilityLine', '', false, false)]
    local procedure MyProcedure2(var ITIICIAvailability: Record "ITI ICI Availability"; JsonObj: JsonObject)
    var
        jsonTok: JsonToken;
    begin
        JsonObj.Get('Description', jsonTok);
        ITIICIAvailability.Description := jsonTok.AsValue().AsText();
        JsonObj.Get('SalesQty', jsonTok);
        ITIICIAvailability."Sales (Qty.)" := jsonTok.AsValue().AsDecimal();
    end;

Customer Balances

The customer balance overview process can be modified in a similar way to the the item availability process described above.

The customer details web service page is based on the customer ledger entry table, so no code is needed to add a new field to the response - simply add it to the page. The code is only needed to read data from the json object.

See Also

Setting up Intercompany Insights

Functionality of Intercompany Insights