Dynamics 365 Business Central: How to bulk delete data on a list page that includes a Card page (For example, bulk delete items on the Item List page)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to briefly talk about how to bulk delete data on a list page that includes a Card page (For example, bulk delete customers on the Customer List page).
I have been seeing this question a lot in the Business Central Forum lately.

As you might know, on some list pages in Business Central, we can select multiple lines and then delete the data in bulk.
For example, on the Payment Terms:

Test video: Very simple

But some list pages don’t work.
Item List:

Customer List:

After selecting multiple lines, the Delete button will be grayed out. Why? Because the CardPageId Property is set on these pages.
CardPageId Property: Use this property on a list page or listpart page to specify the card page that should be displayed when an end user double-clicks an item on the list page or listpart page.

When a page with the CardPageId Property set is added, modified, or deleted, the page set in this property will be opened.

PS: In the shortcut menu, Delete is not grayed out, but clicking it just opens a card page. More details about shortcut menu: Dynamics 365 Business Central: How to add actions to the repeater control shortcut menu (Defining Action Scope)

Because the card page cannot be opened for multiple records at the same time, the system does not allow batch deletion on such a page. So is there a way to do it? In this blog I will introduce three ways,the first two are the standard and the other is custom.

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. Use the questionnaires to tweak things for individual customers of yours. Optionally, use configuration templates to import existing customer data. More details: Dynamics 365 Business Central: How to Export and Import Data (Using Configuration Packages)

On the Config. Package Subform page, there is an Delete Table Records Before Processing field.

Delete Table Records Before Processing
Specifies whether table records should be deleted before the migration process is begun.

When you select the Delete Table Records Before Processing check box, before the data is applied, the existing data in the table will be cleared.

Please note that this method will not execute the OnDelete (Table) trigger of the table, so the data will be cleared directly without any control.

Let’s look at a simple example. Import new items, keep some items, and delete the others.

Choose the New action on the Configuration Packages page.

On the General FastTab, fill in the fields as appropriate. Hover over a field to read a short description.

Enter or select the table number of item, 27.

Select the fields that you want to include from a table.

We can choose Export to Excel to export the template.

Edit this template. This time I only keep three items and then add five more items, Test001~Test005.

Choose Import from Excel to import the template I just edited.

Choose Import.

At this time we can click No. of Package Records to check the data inside.

Then select Delete Table Records Before Processing check box.

Choose Apply Package.

Choose Yes.

Done.

Test video:

PS: Because the data is deleted before it is applied, even if an error occurs, the data has been cleared.

PS: Dynamics 365 Business Central: How to show all error messages in Configuration Package

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

PS: Dynamics 365 Business Central: How to use Edit in Excel in the browser/web (Excel Online)

Yes, the Edit in Excel function supports deleting data.

But please note that this will execute OnDelete (Table) trigger just like deleting on the BC page.

Details: The deletion of a row in data set Item_Card_Excel was not published. Error message: ‘You cannot delete Item 1896-S because there is at least one outstanding Purchase Order that includes this item. CorrelationId: 180c0416-0621-4d18-8d11-2107a3e556b3.’

Test video:

PS:
1. Dynamics 365 Business Central: Switching environments and companies directly in the Edit in Excel file

2. Dynamics 365 Business Central: How to add custom fields in Edit in Excel

Customization

This is quite straightforward. We can create a new action to batch delete the items selected by the user. Of course, we need to execute OnDelete (Table) trigger.
A simple example:

As with deleting from the card page, this will run OnDelete (Table) trigger.

Test video:

Test code:

pageextension 50103 ItemListExt extends "Item List"
{
    actions
    {
        addafter(CopyItem)
        {
            action(BulkDeleteSelectedItems)
            {
                Caption = 'Bulk Delete Selected Items';
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Image = Delete;

                trigger OnAction()
                var
                    Item: Record "Item";
                begin
                    Item.Reset();
                    CurrPage.SetSelectionFilter(Item);
                    if Item.FindSet() then
                        Item.DeleteAll(true);
                end;
            }
        }
    }
}

There is another way to customize it, which is to create a new list page that is not good to contain CardPageId Property, for example, a new Item List page. I will not introduce it in detail this time.

That’s all. If you have this requirement, I personally recommend using the second or third method. Although using Configuration Package does not require customization, it will cause some problems, such as accidentally deleting all data, the data in the associated table has not been deleted, accidentally editing existing data, etc.

Great, give it a try!!!😁

PS:
1. Dynamics 365 Business Central: Bulk update records/fields

2. Dynamics 365 Business Central: Bulk add/update Item Attributes (Edit the attributes of multiple items at the same time) – Customization

3. Dynamics 365 Business Central: Double Click trigger on the list page???

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL