Dynamics 365 Business Central: Import Multiple Customer Pictures (Customization)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to briefly discuss a specific requirement, how to import multiple customer pictures. This was a question from a partner last week.

As you might know, on the Customer Card page, we can add a picture for a signle customer, but as of now, it is not possible to import multiple pictures for multiple customers at the same time in the standard BC.

We discussed how to import files from a zip file (Bulk import attachements and Excel files) last year, you can also directly refer to this post, which includes importing multiple attachments and multiple excel files in zip file.

In fact, for this specific requirement, there is a very good standard feature for reference, Import Item Pictures feature. You can find out more about Import Multiple Item Pictures from MS Learn (Docs).

With this feature, you can import multiple item pictures in one go. Simply name your picture files with names corresponding to your item numbers, compress them to a zip file, and then use the Import Item Pictures page to manage which item pictures to import.

So you can refer to the standard codes of page 348 “Import Item Pictures” and table 31 “Item Picture Buffer”.

Well, let’s get back to the topic. This time we don’t need the “Import Customer Pictures” page, just select the zip file on the Customer List page, and then import multiple customer pictures in one go. Let me do a simple sample.

First add an Import button to the customer list.

Then add import logic: Like Import Item Pictures feature, simply name your files with names corresponding to your customer numbers.

When the customer does not exist, an error will be prompted.

Displays the number of imported pictures when the import is complete.

Test video:

It’s not very difficult. Others such as Vendors and Contacts can also use this method. Give it a try!!!😁

PS: Dynamics 365 Business Central: FileManagement.BLOBExport only save last file? -> Adding multiple files into a zip file

Source Code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)

pageextension 50100 CustomerListExt extends "Customer List"
{
    actions
    {
        addafter("Sent Emails")
        {
            action(ImportMultipleCustomerPictures)
            {
                Caption = 'Import Multiple Customer Pictures';
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Image = Import;
                ToolTip = 'Import Multiple Customer Pictures';

                trigger OnAction()
                begin
                    ImportMultipleCustomerPicturesFromZip();
                end;
            }
        }
    }

    local procedure ImportMultipleCustomerPicturesFromZip()
    var
        FileMgt: Codeunit "File Management";
        DataCompression: Codeunit "Data Compression";
        TempBlob: Codeunit "Temp Blob";
        EntryList: List of [Text];
        EntryListKey: Text;
        ZipFileName: Text;
        FileName: Text;
        FileExtension: Text;
        InStream: InStream;
        EntryOutStream: OutStream;
        EntryInStream: InStream;
        Length: Integer;
        SelectZIPFileMsg: Label 'Select ZIP File';
        FileCount: Integer;
        Cust: Record Customer;
        //DocAttach: Record "Document Attachment";
        NoCustError: Label 'Customer %1 does not exist.';
        ImportedMsg: Label '%1 pictures imported successfully.';
    begin
        //Upload zip file
        if not UploadIntoStream(SelectZIPFileMsg, '', 'Zip Files|*.zip', ZipFileName, InStream) then
            Error('');

        //Extract zip file and store files to list type
        DataCompression.OpenZipArchive(InStream, false);
        DataCompression.GetEntryList(EntryList);

        FileCount := 0;

        //Loop files from the list type
        foreach EntryListKey in EntryList do begin
            FileName := CopyStr(FileMgt.GetFileNameWithoutExtension(EntryListKey), 1, MaxStrLen(FileName));
            FileExtension := CopyStr(FileMgt.GetExtension(EntryListKey), 1, MaxStrLen(FileExtension));
            TempBlob.CreateOutStream(EntryOutStream);
            DataCompression.ExtractEntry(EntryListKey, EntryOutStream, Length);
            TempBlob.CreateInStream(EntryInStream);

            //Import each file where you want
            if not Cust.Get(FileName) then
                Error(NoCustError, FileName);
            Clear(Cust.Image);
            Cust.Image.ImportStream(EntryInStream, FileName);
            Cust.Modify(true);
            FileCount += 1;
        end;

        //Close the zip file
        DataCompression.CloseZipArchive();

        if FileCount > 0 then
            Message(ImportedMsg, FileCount);
    end;
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL