NAV24 Logo
  • Homepage
EN | PL
Show / Hide Table of Contents

Adding custom fields to the "Find Item" page

Required objects

Codeunit holds an Event Subscriber, TableExtension extends N24I Find Item Result table, PageExtension extends N24I Find Item table.

Table Extension - required fields

  • Decimal field. This will be shown to the user.
  • Decimal FlowField. Used to calculate the decimal field above. The CalcFormula will calculate the sum of all items for each type of document. Filters will vary depending on the document type.

Example - calculating quantity for production documents

Below we present an example of how to add your own custom field to the Find Item page. We will provide a way for users to see the quantity found under production documents. We are going to modify the Inventory Availability accordingly with the value of our field. This example will also show you how to add the preview (drill-down) window that will open after a user clicks on your field.

Calculating the custom field

To add a custom field to the Find Item page, you need to extend the table, and page. Let's start with adding the field and the logic behind it to calculate the value of the custom field.

  1. Table Extension Create a new Table Extension that extends the N24I Find Item Result table. Add two new fields, as shown below. The first one will be shown to the user. It's a standard decimal field.

The second one is a flowfield. It will be hidden from the user. For the field to work, you need to write a correct CalcFormula. It will be different for each document type. The "Variant Code" found in the calcformula is specific. It uses the built-in FlowFilter from the base table that you are extending. It will be empty when the user doesn't want to use variant codes. It will hold the value of the current variant code otherwise.

Here is the complete Table Extension:

tableextension 51111 "MyTableExtension" extends "N24I Find Item Result"
{
    fields
    {
        field(51111; "Qty. on Prod Order"; Decimal) //Standard decimal field
        {
            Caption = 'Qty. on Prod Order';
            DataClassification = CustomerContent;
            DecimalPlaces = 0 : 5;
        }
        field(51112; "FlowField_Qty.onProdOrder"; Decimal) //Hidden FlowField
        {
            FieldClass = FlowField;
            CalcFormula = sum("Prod. Order Line"."Remaining Qty. (Base)" where( //We sum all the items found in the "Prod. Order Line" table
                Status = filter(Planned .. Released), //Filter status code
                "Item No." = field("Item No."), //Get only the current item no.
                "Location Code" = field("Location Code"), //For the current location.
                "Variant Code" = field(FlowFilter_VariantCode))); //With a current variant, if available
            Editable = false;
            DecimalPlaces = 0 : 5;
        }
    }
}
  1. Codeunit The codeunit includes an Event Subscriber that fires before each searched item is inserted into the table.

It allows you to modify the values of added custom fields. The subscribing procedure receives a record with the item that will be added to the table after our modifications.

CalcFields calculates the FlowField that was added in the previous step. Validate assigns the value from the calculated FlowField to the field that the user will see. Then we add the value of our field to Qty. Available, which stores the actual stock availability.

Warning

We can add OR subtract the value of the field Qty. Available depending on the purpose of the document. In this case, we add value, because after the production of a given stock, its quantity will increase.

codeunit 51111 "MyCodeunit"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"N24I Item Inventory", 'OnBeforeInventorySearchResultInsertEvent', '', false, false)]
    local procedure MyProcedure(var SearchResult: Record "N24I Find Item Result")
    begin
        SearchResult.CalcFields("FlowField_Qty.onProdOrder");
        SearchResult.Validate("Qty. on Prod Order", SearchResult."FlowField_Qty.onProdOrder");
        SearchResult."Qty. Available" += SearchResult."Qty. on Prod Order";
    end;
}
  1. Page Extension We also need to add our field to the page that the user will see. To do this, we extend the page that the user will see.
pageextension 51111 "MyPageExtension" extends "N24I Find Item"
{
    layout
    {
        addlast(SearchResults)
        {
            field("Qty. on Prod Order"; Rec."Qty. on Prod Order")
            {
                ApplicationArea = All;
            }
        }
    }
}

After these changes, a new field will be displayed to the user. It will be calculated for each item that is added to the table. In this way, we will also affect the value of inventory availability, providing the user with real data for the found inventory.

Adding a document preview for a custom field.

In the previous step, you added fields that are now calculated. To provide the user with full functionality, a lookup must be added. To do this, we need to go back to our Page Extension that was created in the previous step.

We add the OnDrillDown trigger to the previously inserted field, which is triggered after the user clicks on our field. First, we filter the table to show the user only what made the calculated availability the way it is.

Then we run the procedure, that will get the default preview page and filter it. After this action, our field gained the functionality of opening a preview for the selected item on the Find Item page.

pageextension 51111 "MyPageExtension" extends "N24I Find Item"
{
    layout
    {
        addlast(SearchResults)
        {
            field("Qty. on Prod Order"; Rec."Qty. on Prod Order")
            {
                ApplicationArea = All;

                trigger OnDrillDown()
                var
                    ProdOrderLine: Record "Prod. Order Line";

                begin
                    // First we filter the records from Prod. Order Line table
                    ProdOrderLine.SetRange(Status, Enum::"Production Order Status"::Planned, Enum::"Production Order Status"::Released);
                    ProdOrderLine.SetFilter("Item No.", Rec."Item No.");
                    ProdOrderLine.SetFilter("Location Code", Rec."Location Code");
                    if (Rec."Variant Code" <> '') then // We filter the variant code only if it's not empty
                        ProdOrderLine.SetFilter("Variant Code", Rec."Variant Code");

                    // We run the procedure that will open the default lookup page
                    RunDefaultLookupPageForRec(ProdOrderLine);
                end;
            }
        }
    }
}

Complete extension code

tableextension 51111 "MyTableExtension" extends "N24I Find Item Result"
{
    fields
    {
        field(51111; "Qty. on Prod Order"; Decimal) //Standard decimal field
        {
            Caption = 'Qty. on Prod Order';
            DataClassification = CustomerContent;
            DecimalPlaces = 0 : 5;
        }
        field(51112; "FlowField_Qty.onProdOrder"; Decimal) //Hidden FlowField
        {
            FieldClass = FlowField;
            CalcFormula = sum("Prod. Order Line"."Remaining Qty. (Base)" where( //We sum all the items found in the "Prod. Order Line" table
                Status = filter(Planned .. Released), //Filter status code
                "Item No." = field("Item No."), //Get only the current item no.
                "Location Code" = field("Location Code"), //For the current location.
                "Variant Code" = field(FlowFilter_VariantCode))); //With a current variant, if available
            Editable = false;
            DecimalPlaces = 0 : 5;
        }
    }
}

pageextension 51111 "MyPageExtension" extends "N24I Find Item"
{
    layout
    {
        addlast(SearchResults)
        {
            field("Qty. on Prod Order"; Rec."Qty. on Prod Order")
            {
                ApplicationArea = All;

                trigger OnDrillDown()
                var
                    ProdOrderLine: Record "Prod. Order Line";

                begin
                    // First we filter the records from Prod. Order Line table
                    ProdOrderLine.SetRange(Status, Enum::"Production Order Status"::Planned, Enum::"Production Order Status"::Released);
                    ProdOrderLine.SetFilter("Item No.", Rec."Item No.");
                    ProdOrderLine.SetFilter("Location Code", Rec."Location Code");
                    if (Rec."Variant Code" <> '') then // We filter the variant code only if it's not empty
                        ProdOrderLine.SetFilter("Variant Code", Rec."Variant Code");

                     // We run the procedure that will open the default lookup page
                    RunDefaultLookupPageForRec(ProdOrderLine);
                end;
            }
        }
    }
}

codeunit 51111 "MyCodeunit"
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"N24I Item Inventory", 'OnBeforeInventorySearchResultInsertEvent', '', false, false)]
    local procedure MyProcedure(var SearchResult: Record "N24I Find Item Result")
    begin
        SearchResult.CalcFields("FlowField_Qty.onProdOrder");
        SearchResult.Validate("Qty. on Prod Order", SearchResult."FlowField_Qty.onProdOrder");
        SearchResult."Qty. Available" += SearchResult."Qty. on Prod Order";
    end;
}
In This Article
Any questions? 👉 Contact us: produkty@nav24.pl ↑ Back to top