Dynamics 365 Business Central: Can we add Item Attributes Factbox (9110, ListPart) to Sales Order (42, Document) page??? Yes, But……

Dynamics 365 Business Central

Hi, Readers.
I was asked last week whether it is possible to add Item Attributes Factbox (9110, ListPart) to the Sales Order (42, Document) page.
Today I would like to talk about this topic.

When customers inquire about an item, either in correspondence or in an integrated web shop, they may ask or search according to characteristics, such as height and model year. To provide this customer service, you can assign item attribute values of different types to your items, which can then be used when searching for items. More details: Work with Item Attributes.

After creating item attributes and assigning to items , we can find them in the Factbox of the Item Card and Item List.

Item Attributes Factbox (9110, ListPart):

We previously discussed how to add a Factbox for lines/SubPage (Provider Property).
For example, adding Item Picture (346, CardPart) to Sales Order page:

So can we also simply add Item Attributes Factbox (9110, ListPart) as above? No, it’s not that simple.

If you look at the standard code of the Item List page or the Item Card page, you will find that they are not related by the SubPageLink Property (Sets a link to a Factbox from a page).

Instead, it is calculated every time in trigger OnAfterGetCurrRecord(). So we can not use Provider Property this time.

CurrPage.ItemAttributesFactBox.PAGE.LoadItemAttributesData(“No.”);

page 9110 “Item Attributes Factbox”

And Good to know in Page Parts Overview

  • Parts can either represent self-contained functionality, or can be contextual and exchange information with the hosting page.
  • A part can’t be hosted within another part. Business Central allows a maximum of one level of page nesting.
  • Parts can’t be placed within repeater controls.
  • Parts aren’t intended to be displayed on their own without a hosting page.

So we need to add Item Attributes Factbox to Sales Order first.

Then there is a problem here, because we are selecting the sales lines with item no. in Sales Order Subform page, the calculation of loading item attributes data should be added in the OnAfterGetCurrRecord() trigger of the Sales Order Subform page, but “Item Attributes Factbox” factbox is not added in the Sales Order Subform directly, we can’t access “Item Attributes Factbox” from the Sales Order Subform page.
For example, in Sales Order:

In Sales Order Subform:

But if it is calculated on the Sales Order page, you cannot use the OnAfterGetCurrRecord() trigger of the Sales Order Subform page……

Here is a workaround solution. Add a new action to the Sales Order page to load the Item Attributes data. To make it easier to run, I set a shortcut key, ShortCutKey = ‘Shift+Ctrl+D’

Test Video:

Source Code:

pageextension 50100 ZYSalesOrderExt extends "Sales Order"
{
    layout
    {
        addfirst(factboxes)
        {
            part(ItemAttributesFactBox; "Item Attributes Factbox")
            {
                ApplicationArea = All;
            }
        }
    }

    actions
    {
        addfirst(processing)
        {
            action(LoadItemAttributesData)
            {
                Caption = 'Load Selected Item Attributes Data';
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                PromotedOnly = true;
                ShortCutKey = 'Shift+Ctrl+D';
                ApplicationArea = All;

                trigger OnAction()
                var
                    SalesLinesRec: Record "Sales Line";
                begin
                    SalesLinesRec.Reset();
                    CurrPage.SalesLines.Page.SetSelectionFilter(SalesLinesRec);
                    if SalesLinesRec.FindFirst() then
                        if SalesLinesRec.Type = SalesLinesRec.Type::Item then
                            CurrPage.ItemAttributesFactBox.Page.LoadItemAttributesData(SalesLinesRec."No.");
                end;
            }
        }
    }
}

The other Sales Document pages and Purchase Document pages are handled similarly to the above. But I personally don’t think this is a very good way to go. We should change the solution, as you might know, “Sales Lines”, “Purchase Lines”, “Posted Sales Shipment Lines”, and “Posted Purchase Receipt Lines” are now searchable last month.

So we should advise clients to add “Item Attributes Factbox” to Sales Lines page, not sales order page.

Test Video:

Source Code:

pageextension 50111 ZYSalesLinesExt extends "Sales Lines"
{
    layout
    {
        addfirst(factboxes)
        {
            part(ItemAttributesFactBox; "Item Attributes Factbox")
            {
                ApplicationArea = All;
            }
        }
    }

    trigger OnAfterGetCurrRecord()
    begin
        if Rec.Type = Rec.Type::Item then
            CurrPage.ItemAttributesFactBox.Page.LoadItemAttributesData(Rec."No.");
    end;
}

PS: If you want to clear the data in “Item Attributes Factbox”, just pass the empty Item No. to the function.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL