Hi, Readers.
Today I would like to talk about a question that is often asked, how to update records/fields in bulk in Business Central.
Fields in Business Central may contain different editable data, such as text or currency amounts. Editable fields typically display an input box where you can type or choose a value. Non-editable fields are typically displayed with a gray background.
To modify the value of a field, you must first set focus to that field. You set focus by doing the following actions:
- Use the Tab key. The action selects the entire value.
- Left-click your mouse or similar input device. This action will only select the entire field value if the field is in a list.
For example, on the card page:
On the list page:
More details: Entering Data
But if we want to update multiple records or multiple fields at the same time, is there any good way? In this post, I will briefly share three methods (also work for custom fields)
Using Edit in Excel
The Edit in Excel action is available on most lists. With the Edit in Excel action, you make changes to records in Excel and then publish the changes back to Business Central. More details: Viewing and Editing in Excel From Business Central
For example, choose Edit in Excel on the Item List (31, List) page
This time, for testing, I used Edit in Excel in the browser. More details: Dynamics 365 Business Central: How to use Edit in Excel in the browser/web (Excel Online)
Choose Sign in.
You can see that the data has all been retrieved. (Note that this may not include all fields.)
PS: Dynamics 365 Business Central: How to add custom fields in Edit in Excel
At this point you can modify the information, such as the Description field, Blocked field, etc. and then click Publish.
Publishing
Publish successful
Go back to the BC page and press F5 to find that the data has been updated.
Test video:
PS:
1. Dynamics 365 Business Central: How to use Edit in Excel in the browser/web (Excel Online)
2. Dynamics 365 Business Central: How to add custom fields in Edit in Excel
Using Configuration Package
When you onboard a prospect, you can use Configuration Packages to set up Business Central according to your best practices and their requirements. Apply the relevant configuration packages to an empty company in the customer’s tenant. In brief, Configuration Packages is an alternative method to “Edit in Excel” to upload lots of data into Microsoft Dynamics 365 Business Central. This was called “RapidStart” in the Navision days. More details: Dynamics 365 Business Central: How to Export and Import Data (Using Configuration Packages)
This function can also be used to update data. Just keep the primary key unchanged. Let’s look at a simple example.
I added the Item (27) table and choose Fields.
Just like Edit in Excel above, select the fields that need to be updated. This includes all fields.
As long as we keep the primary key (“No.”) unchanged, we can update the value of the field we just exported. If you modify the primary key, the records in Excel will be imported into the system as new records.
Import Excel file and apply configuration package.
Great.
Test video:
PS:
1. Dynamics 365 Business Central: How to Export and Import Data (Using Configuration Packages)
3. Dynamics 365 Business Central: How to show all error messages in Configuration Package
Customization
This is the last resort. I personally recommend that if it can be done with standard features, try not to consider customization.
There are many ways to customize, we have discussed similar requirements before. For example, 1. Dynamics 365 Business Central: Bulk add/update Item Attributes (Edit the attributes of multiple items at the same time) – Customization
2. Dynamics 365 Business Central: How to bulk edit user roles/profiles (Customization)
Of course hard coding is not recommended, so let’s look at a simple example, Bulk updating Item Description.
PS: Dynamics 365 Business Central: How to get a filter for the selected records on any page (For example, ‘1..3|6’)
Dialog page:
And, new action
Test:
Great.
Test video: This method works for any field in any table that is editable
Source code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)
pageextension 50203 ItemListExt extends "Item List"
{
actions
{
addfirst(processing)
{
action(BulkUpdateItemDescription)
{
ApplicationArea = All;
Caption = 'Bulk update Item Description';
Promoted = true;
PromotedCategory = Process;
Image = Open;
trigger OnAction()
var
UpdateItemDescriptionDialog: Page "Update Item Description Dialog";
Item: Record Item;
ItemFilter: Code[250];
SelectionFilterManagement: Codeunit SelectionFilterManagement;
begin
Item.Reset();
CurrPage.SetSelectionFilter(Item);
if not Item.IsEmpty then
ItemFilter := SelectionFilterManagement.GetSelectionFilterForItem(Item);
UpdateItemDescriptionDialog.GetSelectionFilter(ItemFilter);
if UpdateItemDescriptionDialog.RunModal() = Action::OK then
UpdateItemDescriptionDialog.UpdateItemDescription();
end;
}
}
}
}
page 50200 "Update Item Description Dialog"
{
PageType = StandardDialog;
Caption = 'Update Item Description Dialog';
layout
{
area(content)
{
field(ItemFilter; ItemFilter)
{
ApplicationArea = All;
Caption = 'Item Filter';
Editable = false;
}
field(NewItemDescription; NewItemDescription)
{
ApplicationArea = All;
Caption = 'New Item Description';
}
}
}
var
ItemFilter: Code[250];
NewItemDescription: Text[100];
procedure GetSelectionFilter(ItemPageFilter: Code[250])
begin
ItemFilter := '';
ItemFilter := ItemPageFilter;
end;
procedure UpdateItemDescription()
var
Item: Record Item;
begin
Item.Reset();
Item.SetFilter("No.", ItemFilter);
if Item.FindSet() then
repeat
Item.Validate(Description, NewItemDescription);
Item.Modify(true);
until Item.Next() = 0;
end;
}
Very simple, give it a try!!!😁
PS:
1. Dynamics 365 Business Central: Can we skip/ignore field validation errors?
END
Hope this will help.
Thanks for reading.
ZHU
コメント