Hi, Readers.
Today I would like to talk about how to add Filter by item attributes to the Item Ledger Entries page.
Let’s take a look at item attributes feature briefly. 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.
For example, 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.



Test video: Filter by item attributes on the Item List page
Yesterday, we discussed how to add the Item Attributes FactBox (9110, ListPart) to the Item Ledger Entries page.

Can we also add the “Filter by item attributes” feature to other pages like Item Ledger Entries?
Let’s look at the standard logic: page 31, “Item List” -> action(FilterByAttributes)
There is a standard process here that returns a Filter Text containing the range of all applicable Item Nos., and then performs the filtering.

This can be confirmed in the Item List. For example,


So we need to port the entire logic over to the Item Ledger Entries page. Let’s check out my test results.
Filter By Attributes:

Clear Attributes:

Other procedures:

On the Item Ledger Entries page:

Test:

Done.


Test video:
Great. Give it a try!!!😁
Source code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)
pageextension 50119 ItemLedgerEntries extends "Item Ledger Entries"
{
layout
{
addfirst(factboxes)
{
part(ItemAttributesFactBox; "Item Attributes FactBox")
{
ApplicationArea = All;
}
}
}
actions
{
addbefore("&Value Entries")
{
action(FilterByAttributes)
{
AccessByPermission = TableData "Item Attribute" = R;
ApplicationArea = Basic, Suite;
Caption = 'Filter by Attributes';
Image = EditFilter;
Promoted = true;
PromotedCategory = Process;
ToolTip = 'Find items that match specific attributes. To make sure you include recent changes made by other users, clear the filter and then reset it.';
trigger OnAction()
var
ItemAttributeManagement: Codeunit "Item Attribute Management";
TypeHelper: Codeunit "Type Helper";
CloseAction: Action;
FilterText: Text;
FilterPageID: Integer;
ParameterCount: Integer;
begin
FilterPageID := PAGE::"Filter Items by Attribute";
if ClientTypeManagement.GetCurrentClientType() = CLIENTTYPE::Phone then
FilterPageID := PAGE::"Filter Items by Att. Phone";
CloseAction := PAGE.RunModal(FilterPageID, TempFilterItemAttributesBuffer);
if (ClientTypeManagement.GetCurrentClientType() <> CLIENTTYPE::Phone) and (CloseAction <> ACTION::LookupOK) then
exit;
if TempFilterItemAttributesBuffer.IsEmpty() then begin
ClearAttributesFilter();
exit;
end;
TempItemFilteredFromAttributes.Reset();
TempItemFilteredFromAttributes.DeleteAll();
ItemAttributeManagement.FindItemsByAttributes(TempFilterItemAttributesBuffer, TempItemFilteredFromAttributes);
FilterText := ItemAttributeManagement.GetItemNoFilterText(TempItemFilteredFromAttributes, ParameterCount);
if ParameterCount < TypeHelper.GetMaxNumberOfParametersInSQLQuery() - 100 then begin
Rec.FilterGroup(0);
Rec.MarkedOnly(false);
Rec.SetFilter("Item No.", FilterText);
end else begin
RunOnTempRec := true;
Rec.ClearMarks();
Rec.Reset();
end;
end;
}
action(ClearAttributes)
{
AccessByPermission = TableData "Item Attribute" = R;
ApplicationArea = Basic, Suite;
Caption = 'Clear Attributes Filter';
Image = RemoveFilterLines;
Promoted = true;
PromotedCategory = Process;
ToolTip = 'Remove the filter for specific item attributes.';
trigger OnAction()
begin
ClearAttributesFilter();
TempItemFilteredFromAttributes.Reset();
TempItemFilteredFromAttributes.DeleteAll();
RunOnTempRec := false;
RestoreTempItemFilteredFromAttributes();
end;
}
}
}
var
TempFilterItemAttributesBuffer: Record "Filter Item Attributes Buffer" temporary;
TempItemFilteredFromAttributes: Record Item temporary;
ClientTypeManagement: Codeunit "Client Type Management";
RunOnTempRec: Boolean;
trigger OnAfterGetCurrRecord()
begin
CurrPage.ItemAttributesFactBox.Page.LoadItemAttributesData(Rec."Item No.");
end;
local procedure ClearAttributesFilter()
begin
Rec.ClearMarks();
Rec.MarkedOnly(false);
TempFilterItemAttributesBuffer.Reset();
TempFilterItemAttributesBuffer.DeleteAll();
Rec.FilterGroup(0);
Rec.SetRange("Item No.");
end;
local procedure RestoreTempItemFilteredFromAttributes()
begin
TempItemFilteredFromAttributes.Reset();
TempItemFilteredFromAttributes.DeleteAll();
RunOnTempRec := true;
end;
}PS:
1. Dynamics 365 Business Central: Show Item Attributes on the page (For Example: On Item List page)
2. Dynamics 365 Business Central: Can we add Item Attributes Factbox (9110, ListPart) to Sales Order (42, Document) page??? Yes, But……
3. Dynamics 365 Business Central: Bulk add/update Item Attributes (Edit the attributes of multiple items at the same time) – Customization
END
Hope this will help.
Thanks for reading.
ZHU




コメント