Sunday, January 30, 2022

Print QR Code & Data Matrix in Business Central SaaS Version - New Very Simple Method

Hello Friends, 

From BC 19.1 version 2D Fonts available in BC Version (Free !!!!)

Microsoft added this feature 

Simple 4 line code to generate it.

report 67467 ItemBarCode
{
    UsageCategory = Administration;
    ApplicationArea = All;
    DefaultLayout = RDLC;
    Caption = 'Item Barcodes';
    RDLCLayout = 'ItemBarcodes.rdl';
    dataset
    {
        dataitem(Item; Item)
        {
            DataItemTableView = sorting("No.");
            RequestFilterFields = "No.";
            RequestFilterHeading = 'Items';
            column(No_; "No.")
            {
            }
            column(Description; Description)
            {
            }
            column(DataMatrix; DataMatrix)
            {
            }
            column(QRCode; QRCode)
            {
            }
            trigger OnAfterGetRecord()
            begin
                GenerateDataMatrix();
                GenerateQRCode();
            end;
        }
    }

    local procedure GenerateDataMatrix()
    var
        BarcodeSymbology2D: Enum "Barcode Symbology 2D";
        BarcodeFontProvider2D: Interface "Barcode Font Provider 2D";
        BarcodeString: Text;
    begin
        BarcodeFontProvider2D := Enum::"Barcode Font Provider 2D"::IDAutomation2D;
        BarcodeSymbology2D := Enum::"Barcode Symbology 2D"::"Data Matrix";
        BarcodeString := Item."No.";
        DataMatrix := BarcodeFontProvider2D.EncodeFont(BarcodeString, BarcodeSymbology2D);
    end;

    local procedure GenerateQRCode()
    var
        BarcodeSymbology2D: Enum "Barcode Symbology 2D";
        BarcodeFontProvider2D: Interface "Barcode Font Provider 2D";
        BarcodeString: Text;
    begin
        BarcodeFontProvider2D := Enum::"Barcode Font Provider 2D"::IDAutomation2D;
        BarcodeSymbology2D := Enum::"Barcode Symbology 2D"::"QR-Code";
        BarcodeString := Item."No." + ' | ' + Item.Description + '|' + Format(CurrentDateTime);
        QRCode := BarcodeFontProvider2D.EncodeFont(BarcodeString, BarcodeSymbology2D);
    end;

    var

        DataMatrix: Text;

        QRCode: Text;
}

Create Layout and enter font name manual in text box









Font Name - IDAutomation2D

Note – Font name not available in list but you can simple enter it manual, It will work fine.



















Done…..

So Simple…..










I hope this blog help someone to develop it.

Thank you for reading...

Keep Sharing....Keep Growing....

Saturday, January 29, 2022

Import Picture or Attachment in Bulk in Business Central (From Zip Comparess File)

 Hello Friends,

 We develop the functionality to bulk import Attachment or Pictures on below master document

  • Customer
  • Vendor
  • Item
  • Fixed Asset

 There is two new action added on List Page for

  • Import Attachment Zip File
  • Import Image Zip File

 You need create one folder and put the image files where file name must be match with primary key of record (Like Customer No.)


compress this folder and make Zip File




Now come to respected list page and where you can see below action to impot it.




Above customer no. created for demo purpose where we going to bulk import image file

 After import zip system update picture on customer master !!!!












Same way we can import attachments again records.

 Technical Code Details : (for developer only !!!!)

===


pageextension 74981 CustomerListExtP74981 extends "Customer List"
{
    actions
    {
        addafter("Sent Emails")
        {
            action(ImportZipFile)
            {
                Caption = 'Import Zip File (Attachment)';
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Image = Import;
                ToolTip = 'Import Attachments from Zip';

                trigger OnAction()
                begin
                    ImportAttachmentsFromZip();
                end;
            }
            action(ImportPictureFile)
            {
                Caption = 'Import Zip File (Picture)';
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Image = Import;
                ToolTip = 'Import Picture from Zip';

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

    local procedure ImportAttachmentsFromZip()
    var
        FileMgt: Codeunit "File Management";
        DataCompression: Codeunit "Data Compression";
        TempBlob: Codeunit "Temp Blob";
        EntryList: List of [Text];
        EntryListKey: Text;
        ZipFileName: Text;
        Window: Dialog;
        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 attachments Imported successfully.';
        Cnt_lInt: Integer;
    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;

        Window.Open('#1##############################');

        //Loop files from the list type
        foreach EntryListKey in EntryList do begin
            Cnt_lInt += 1;
            Window.Update(1, Cnt_lInt);

            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);

            DocAttach.Init();
            DocAttach.Validate("Table ID", Database::Customer);
            DocAttach.Validate("No.", FileName);
            DocAttach.Validate("File Name", FileName);
            DocAttach.Validate("File Extension", FileExtension);
            DocAttach."Document Reference ID".ImportStream(EntryInStream, FileName);
            DocAttach.Insert(true);
            FileCount += 1;
        end;

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

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

    procedure LoadZIPPictureFile(): Text
    var
        Item: Record Item;
        FileMgt: Codeunit "File Management";
        DataCompression: Codeunit "Data Compression";
        TempBlob: Codeunit "Temp Blob";
        Window: Dialog;
        EntryList: List of [Text];
        EntryListKey: Text;
        InStream: InStream;
        EntryOutStream: OutStream;
        EntryInStream: InStream;
        Length: Integer;
        FileName: Text;
        FileExtension: Text;
        Cust: Record Customer;
        NoCustError: Label 'Customer %1 does not exist.';
        ImportedMsg: Label '%1 attachments Imported successfully.';
        ZipFileName: Text;
        Cnt_lInt: Integer;
    begin
        if not UploadIntoStream(SelectZIPFileMsg, '', 'Zip Files|*.zip', ZipFileName, InStream) then
            Error('');

        DataCompression.OpenZipArchive(InStream, false);
        DataCompression.GetEntryList(EntryList);

        Window.Open('#1##############################');

        foreach EntryListKey in EntryList do begin
            Cnt_lInt += 1;
            Window.Update(1, Cnt_lInt);

            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);

            Cust.Image.ImportStream(EntryInStream, FileMgt.GetFileName(EntryListKey));
            Cust.Modify();
        end;

        DataCompression.CloseZipArchive;
        Window.Close;

        exit(ZipFileName);
    end;

    var
        SelectZIPFileMsg: Label 'Select ZIP File';

}

I hope this help some one.

Keep Sharing....Keep Growing....

Friday, January 28, 2022

Using Instream & Outstream set as Source and Run XMLPort - Export and Import Data

Hello Friends,

By using Instream & Outstream set as Source and Run XMLPort - Export and Import Data

codeunit 90000 "VTK High Radius Int Unit Test"

{
    Subtype = Test;
    TestPermissions = Disabled;

    [Test]
    [TransactionModel(TransactionModel::AutoRollback)]

    procedure "1A. HighRadius AR Export"()
    var
        HighRadARExport: xmlport "HighRadius AR Export";
        VarOutstream: OutStream;
        VarInStream: InStream;
        ExpFileName: Text;
        DataExport: Text;
        TempBlob: Codeunit "Temp Blob";
    begin
        Clear(TempBlob);
        TempBlob.CreateInStream(VarInStream);
        TempBlob.CreateOutStream(VarOutstream);
        Clear(HighRadARExport);
        HighRadARExport.SetDestination(VarOutstream);
        HighRadARExport.Export();
        VarInStream.ReadText(DataExport);
        IF StrLen(DataExport) = 0 then
            Error('There is no data export');
    end;

    [Test]
    [TransactionModel(TransactionModel::AutoRollback)]

    procedure "1A. HighRadius Customer Export"()
    var
        HighRadCustExport: XmlPort "HighRadius Customer Export";
        VarOutstream: OutStream;
        VarInStream: InStream;
        DataExport: Text;
        TempBlob: Codeunit "Temp Blob";
    begin
        Clear(TempBlob);
        TempBlob.CreateInStream(VarInStream);
        TempBlob.CreateOutStream(VarOutstream);
        Clear(HighRadCustExport);
        HighRadCustExport.SetDestination(VarOutstream);
        HighRadCustExport.Export();
        VarInStream.ReadText(DataExport);
        IF StrLen(DataExport) = 0 then
            Error('There is no data export');
    end;

    [Test]
    [TransactionModel(TransactionModel::AutoRollback)]

    procedure "1A. HighRadius DMS Extract Import"()
    var
        HighRadDMSEXtrImport: xmlport "HighRadius DMS Extract Import";
        VarOutstream: OutStream;
        VarInStream: InStream;

        TempBlob: Codeunit "Temp Blob";
        VarFileData: Text;
        LFChar: Text[1];
        DocInsertCount: Integer;
    begin
        Clear(TempBlob);

        TempBlob.CreateOutStream(VarOutstream);

        LFChar[1] := 10;  //LF

        VarFileData := 'DEDUCTION_ID|DEDUCTION_TYPE';
        VarFileData += LFChar;
        VarFileData += '13976|Pre-Deduction';
        VarFileData += LFChar;
        VarFileData += '13977|Pre-Deduction';

        VarOutstream.WriteText(VarFileData);
        TempBlob.CreateInStream(VarInStream);

        HighRadDMSEXtrImport.SETSOURCE(varInstream);
        HighRadDMSEXtrImport.SetRunFromTestCodeunit();
        HighRadDMSEXtrImport.IMPORT();
        DocInsertCount := HighRadDMSEXtrImport.GetOrderInsertCount();

        IF DocInsertCount = 0 then
            Error('There is nothing to import');




    end;

    [Test]
    [TransactionModel(TransactionModel::AutoRollback)]

    procedure "1A. HighRadius Payment Import"()
    var
        HighRadPaymentImport: XmlPort "HighRadius Payment Import";
        VarOutstream: OutStream;
        VarInStream: InStream;
        CRLFChar: Text[2];
        VarFileData: Text;
        TempBlob: Codeunit "Temp Blob";
        DocInsertCount: Integer;
    begin
        Clear(TempBlob);

        TempBlob.CreateOutStream(VarOutstream);

        CRLFChar[1] := 13; // CR - Carriage Return
        CRLFChar[2] := 10; // LF - Line Feed

        VarFileData := 'Bank Account Number,Currency,Payment Type';
        VarFileData += CRLFChar;
        VarFileData += '306262556,AUD,Wire';

        VarOutstream.WriteText(VarFileData);
        TempBlob.CreateInStream(VarInStream);

        HighRadPaymentImport.SETSOURCE(varInstream);
        HighRadPaymentImport.SetRunFromTestCodeunit();
        HighRadPaymentImport.IMPORT();
        DocInsertCount := HighRadPaymentImport.GetGenLineInsertCount();

        IF DocInsertCount = 0 then
            Error('There is nothing to import');



    end;


}

Very useful for create Import & Export XMLPort Test Codeunit creation

Thank you.