Dynamics 365 Business Central: Show Item Attributes on the page (For Example: On Item List page)

Dynamics 365 Business Central

Hello Readers.
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. Item attributes was released from NAV 2017.
This time I’d like to talk about how to show Item Attributes on the page.

Work with Item Attributes

First, let’s take a look at this feature briefly.
With Item Attributes, you can create item attributes on Item Attributes page.

And create values for item attributes of type Option

Then you can assign item attributes to items.

Finally, you can find Item Attributes in the Factbox of the Item Card and Item List.

You can also filter by item attributes on Item List page.

PS:
1. You can assign item attributes to item categories.

2. You can add Translations for Item Attributes and Item Attribute Values.
Item Attributes:

Item Attribute Values:

Change language to Japanese:

In summary, this is very cool feature that you can add attributes of items freely without any customization. But perhaps Microsoft is concerned about performance issues of Business Central, you cannot find Item Attributes directly on the page and download to an Excel sheet.

MS DOCS:
Work with Item Attributes

Show Item Attributes on the page

This function is very similar to Dimensions, so this time, let me refer to standard Dimensions feature, and add Item Attributes to the Item list page.

If you want to customize item attributes, you need to pay attention to these three tables.
1. Item Attribute (7500)

2. Item Attribute Value (7501)

3. Item Attribute Value Mapping (7505)

The essentials design explains:
1. On Inventory Setup page, add the Item attributes you need to shown on the page. For example: “Shortcut Item Attribute 1” ~ “Shortcut Item Attribute 4”

2. Only the item attributes set on Inventory Setup page will be shown on Item List page, and the Caption of the column must be correctly obtained.

3. It must be noted that there are translations for Item Attributes.

OK, Let’s start.

1. Use tableextension to add fields to table 313 “Inventory Setup”
“Shortcut Item Attribute 1” ~ “Shortcut Item Attribute 4” Integer

2. Show fields on page 461 “Inventory Setup”

3. Create a new PageExtension for page 31 “Item List”

4. Define global variables
ShorcutItemAttribute1~ShorcutItemAttribute4: Show Item Attribute Values on the page.
Caption01~Caption04: Change field captions dynamically.
Visable01~Visable04: Sets whether to show the fields on the page.

5. Show fields on page 31 “Item List”
Note:
CaptionClass = ‘1,5,,’ + Caption01;…
Visible = Visable01;…

6. Set Caption Data of fields and set Item Attribute Values on “OnAfterGetRecord” trigger.

Source Code:

    local procedure SetCaptionData()
    var
        ItemAttribute: Record "Item Attribute";
        InventorySetup: Record "Inventory Setup";
    begin
        Clear(Caption01);
        Clear(Caption02);
        Clear(Caption03);
        Clear(Caption04);
        Clear(Visable01);
        Clear(Visable02);
        Clear(Visable03);
        Clear(Visable04);
        if InventorySetup.Get() then begin
            if ItemAttribute.Get(InventorySetup."Shortcut Item Attribute 1") then begin
                Caption01 := ItemAttribute.GetTranslatedName(GlobalLanguage);
                Visable01 := true;
            end else begin
                Visable01 := false;
            end;

            ItemAttribute.Reset();
            if ItemAttribute.Get(InventorySetup."Shortcut Item Attribute 2") then begin
                Caption02 := ItemAttribute.GetTranslatedName(GlobalLanguage);
                Visable02 := true;
            end else begin
                Visable02 := false;
            end;

            ItemAttribute.Reset();
            if ItemAttribute.Get(InventorySetup."Shortcut Item Attribute 3") then begin
                Caption03 := ItemAttribute.GetTranslatedName(GlobalLanguage);
                Visable03 := true;
            end else begin
                Visable03 := false;
            end;

            ItemAttribute.Reset();
            if ItemAttribute.Get(InventorySetup."Shortcut Item Attribute 4") then begin
                Caption04 := ItemAttribute.GetTranslatedName(GlobalLanguage);
                Visable04 := true;
            end else begin
                Visable04 := false;
            end;
        end;
    end;

    local procedure SetItemAttibuteValue()
    var
        ItemAttributeValueMap: Record "Item Attribute Value Mapping";
        ItemAttributeValue: Record "Item Attribute Value";
        InventorySetup: Record "Inventory Setup";
    begin
        ShorcutItemAttribute1 := '';
        ShorcutItemAttribute2 := '';
        ShorcutItemAttribute3 := '';
        ShorcutItemAttribute4 := '';
        if InventorySetup.Get() then begin
            if ItemAttributeValueMap.Get(Database::Item, Rec."No.", InventorySetup."Shortcut Item Attribute 1") then
                if ItemAttributeValue.Get(ItemAttributeValueMap."Item Attribute ID", ItemAttributeValueMap."Item Attribute Value ID") then
                    ShorcutItemAttribute1 := ItemAttributeValue.GetTranslatedName(GlobalLanguage);

            ItemAttributeValueMap.Reset();
            ItemAttributeValue.Reset();
            if ItemAttributeValueMap.Get(Database::Item, Rec."No.", InventorySetup."Shortcut Item Attribute 2") then
                if ItemAttributeValue.Get(ItemAttributeValueMap."Item Attribute ID", ItemAttributeValueMap."Item Attribute Value ID") then
                    ShorcutItemAttribute2 := ItemAttributeValue.GetTranslatedName(GlobalLanguage);

            ItemAttributeValueMap.Reset();
            ItemAttributeValue.Reset();
            if ItemAttributeValueMap.Get(Database::Item, Rec."No.", InventorySetup."Shortcut Item Attribute 3") then
                if ItemAttributeValue.Get(ItemAttributeValueMap."Item Attribute ID", ItemAttributeValueMap."Item Attribute Value ID") then
                    ShorcutItemAttribute3 := ItemAttributeValue.GetTranslatedName(GlobalLanguage);

            ItemAttributeValueMap.Reset();
            ItemAttributeValue.Reset();
            if ItemAttributeValueMap.Get(Database::Item, Rec."No.", InventorySetup."Shortcut Item Attribute 4") then
                if ItemAttributeValue.Get(ItemAttributeValueMap."Item Attribute ID", ItemAttributeValueMap."Item Attribute Value ID") then
                    ShorcutItemAttribute4 := ItemAttributeValue.GetTranslatedName(GlobalLanguage);
        end;
    end;

7. Publish the extension and confirm.
Show three Item attributes:

Item List:

In Japanese:

Test Video:

Open in excel.

This is just a reference solution, you can enhance or modify it.

Source Code:
https://github.com/yzhums/ItemAttributesExt

Customization reference:
How to change field captions dynamically in Dynamics 365 Business Central
How to add Shortcut Dimensions on the page in Dynamics 365 Business Central (Shortcut Dimension 2 ~ 8)

END

Hope this will help.

Thanks.

コメント

Copied title and URL