Hi, Readers.
Today I would like to talk about a question that has been asked before, is there any way to edit the attributes of multiple items at the same time.
can you tell us how to select many items in page item list and create an action that update the attribute of the selected items in one action.
exemple we selected 3 items when we click on the new action “update attribute” it will appear a page in wich we can add attribute and when we click ok it will be saved for the 3 items
This is an interesting requirement. 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.
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:
More details: Work with Item Attributes
This is very cool feature that you can add attributes of items freely without any customization. But this can only edit the attributes of one item at a time, and you cannot edit multiple items at the same time. So is it possible to do it with customization? Yes, I briefly tested it and it is possible. The most important page to edit attributes is page 7504 “Item Attribute Value List”.
page 7510 “Item Attribute Value Editor”: This is the standard modification page we open.
But the content is in the part.
page 7504 “Item Attribute Value List”:
Below is some of the standard logic for adding and modifying attributes. But you may have noticed that this can only handle one item.
And subscribing to standard events this time cannot achieve such complex customization, so I copied the standard page 7504 “Item Attribute Value List” this time and create a new page. And after selecting items that need to be edited on Item List, the filtered results are passed to the new page.
Modifications or additions on this new page are then applied to all selected items (Item Filter).
Test video: Youtube
Very simple, 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 50115 ItemlistExt extends "Item List"
{
actions
{
addafter(CopyItem)
{
action(BulkEditAttrubute)
{
Caption = 'Bulk Edit Attributes';
Image = Edit;
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
PromotedIsBig = true;
trigger OnAction()
var
Item: Record Item;
ItemAttributesValueList: Page "ZY Item Attributes Value List";
SelectionFilterManagement: Codeunit SelectionFilterManagement;
RecRef: RecordRef;
begin
Item.Reset();
CurrPage.SetSelectionFilter(Item);
RecRef.GetTable(Item);
ItemAttributesValueList.GetSelectionFilter(SelectionFilterManagement.GetSelectionFilter(RecRef, Item.FieldNo("No.")));
ItemAttributesValueList.RunModal();
CurrPage.ItemAttributesFactBox.PAGE.LoadItemAttributesData(Rec."No.");
end;
}
}
}
}
page 50103 "ZY Item Attributes Value List"
{
Caption = 'Item Attributes Values';
DelayedInsert = true;
LinksAllowed = false;
PageType = ListPart;
SourceTable = "Item Attribute Value Selection";
SourceTableTemporary = true;
layout
{
area(content)
{
group(ItemFilters)
{
ShowCaption = false;
field(ItemFilter; ItemFilter)
{
ApplicationArea = All;
Caption = 'Item Filter';
Editable = false;
}
}
repeater(Control1)
{
ShowCaption = false;
field("Attribute Name"; Rec."Attribute Name")
{
ApplicationArea = Basic, Suite;
AssistEdit = false;
Caption = 'Attribute';
TableRelation = "Item Attribute".Name where(Blocked = const(false));
ToolTip = 'Specifies the item attribute.';
trigger OnValidate()
var
ItemAttributeValue: Record "Item Attribute Value";
ItemAttributeValueMapping: Record "Item Attribute Value Mapping";
ItemAttribute: Record "Item Attribute";
Item: Record Item;
begin
Item.Reset();
Item.SetFilter("No.", ItemFilter);
if Item.FindSet() then
repeat
RelatedRecordCode := '';
RelatedRecordCode := Item."No.";
if xRec."Attribute Name" <> '' then begin
xRec.FindItemAttributeByName(ItemAttribute);
DeleteItemAttributeValueMapping(ItemAttribute.ID);
end;
if not Rec.FindAttributeValue(ItemAttributeValue) then
Rec.InsertItemAttributeValue(ItemAttributeValue, Rec);
if ItemAttributeValue.Get(ItemAttributeValue."Attribute ID", ItemAttributeValue.ID) then begin
if not ItemAttributeValueMapping.Get(Database::Item, RelatedRecordCode, ItemAttributeValue."Attribute ID") then begin
ItemAttributeValueMapping.Reset();
ItemAttributeValueMapping.Init();
ItemAttributeValueMapping."Table ID" := Database::Item;
ItemAttributeValueMapping."No." := RelatedRecordCode;
ItemAttributeValueMapping."Item Attribute ID" := ItemAttributeValue."Attribute ID";
ItemAttributeValueMapping."Item Attribute Value ID" := ItemAttributeValue.ID;
ItemAttributeValueMapping.Insert();
end;
end;
until Item.Next() = 0;
end;
}
field(Value; Rec.Value)
{
ApplicationArea = Basic, Suite;
Caption = 'Value';
TableRelation = if ("Attribute Type" = const(Option)) "Item Attribute Value".Value where("Attribute ID" = field("Attribute ID"),
Blocked = const(false));
ToolTip = 'Specifies the value of the item attribute.';
trigger OnValidate()
var
ItemAttributeValue: Record "Item Attribute Value";
ItemAttributeValueMapping: Record "Item Attribute Value Mapping";
ItemAttribute: Record "Item Attribute";
Item: Record Item;
begin
Item.Reset();
Item.SetFilter("No.", ItemFilter);
if Item.FindSet() then
repeat
RelatedRecordCode := '';
RelatedRecordCode := Item."No.";
if not Rec.FindAttributeValue(ItemAttributeValue) then
Rec.InsertItemAttributeValue(ItemAttributeValue, Rec);
ItemAttributeValueMapping.Reset();
ItemAttributeValueMapping.SetRange("Table ID", Database::Item);
ItemAttributeValueMapping.SetRange("No.", RelatedRecordCode);
ItemAttributeValueMapping.SetRange("Item Attribute ID", ItemAttributeValue."Attribute ID");
if ItemAttributeValueMapping.FindFirst() then begin
ItemAttributeValueMapping."Item Attribute Value ID" := ItemAttributeValue.ID;
ItemAttributeValueMapping.Modify();
end;
ItemAttribute.Get(Rec."Attribute ID");
if ItemAttribute.Type <> ItemAttribute.Type::Option then
if Rec.FindAttributeValueFromRecord(ItemAttributeValue, xRec) then
if not ItemAttributeValue.HasBeenUsed() then
ItemAttributeValue.Delete();
until Item.Next() = 0;
end;
}
field("Unit of Measure"; Rec."Unit of Measure")
{
ApplicationArea = Basic, Suite;
ToolTip = 'Specifies the name of the item or resource''s unit of measure, such as piece or hour.';
}
}
}
}
var
ItemFilter: Code[250];
trigger OnOpenPage()
begin
CurrPage.Editable(true);
end;
protected var
RelatedRecordCode: Code[20];
local procedure DeleteItemAttributeValueMapping(AttributeToDeleteID: Integer)
var
ItemAttributeValueMapping: Record "Item Attribute Value Mapping";
ItemAttribute: Record "Item Attribute";
begin
ItemAttributeValueMapping.SetRange("Table ID", Database::Item);
ItemAttributeValueMapping.SetRange("No.", RelatedRecordCode);
ItemAttributeValueMapping.SetRange("Item Attribute ID", AttributeToDeleteID);
if ItemAttributeValueMapping.FindFirst() then begin
ItemAttributeValueMapping.Delete();
end;
ItemAttribute.Get(AttributeToDeleteID);
ItemAttribute.RemoveUnusedArbitraryValues();
end;
procedure GetSelectionFilter(ItemPageFilter: Code[250])
begin
ItemFilter := '';
ItemFilter := ItemPageFilter;
end;
}
PS:
1. Dynamics 365 Business Central: Show Item Attributes on the page (For Example: On Item List page)
END
Hope this will help.
Thanks for reading.
ZHU
コメント