Thursday, November 11, 2021

Import Base 64 Data to BLOB Field in Business Central

 Hello Friends,

To convert base 64 string data to blob field.

Process blob field data to xmlport.

=======

We create the codeunit function to process base 64 data.

Below code will import Base 64 data to Blob field

  procedure FillBase64(Base64Text_iTxt: Text)
    var
        ImportLog_lRec: Record "Import Log Detail";
        VarOutStream: OutStream;
        Base64CU: Codeunit "Base64 Convert";
    begin
        ImportLog_lRec.Init();
        ImportLog_lRec.Insert();
        ImportLog_lRec.CalcFields("File Data");
        ImportLog_lRec."File Data".CreateOutStream(VarOutStream);
        Base64CU.FromBase64(Base64Text_iTxt, VarOutStream);
        ImportLog_lRec.Modify();
    end;

Call webservice function to pass base 64 data in function


























below code will process base 64 data (text import data) and process in xmlport import

CalcFields("File Data");
"File Data".CreateInStream(Instr);

Clear(ImportiMIS_xmlPort);
ImportiMIS_xmlPort.SetSource(Instr);
ImportiMIS_xmlPort.Import();

Download base 64 file blob field data to text file

procedure ExportDataAsText()
    var
      Instr: InStream;
    begin
        if not "File Data".HasValue then
            exit;

        CalcFields("File Data");
        "File Data".CreateInStream(Instr);
        DownloadFromStream(Instr, '', '', '', "File Name");
  end;

Call this web service function from postman

Method: Post

Authentication : Basic

Header: 

SOAPAction : "urn:microsoft-dynamics-schemas/codeunit/ImportSOFile:ImportSO"

Content Type: text/xml;charset=UTF-8

API: https://api.businesscentral.dynamics.com/v2.0/0083fe57-c7f0-4c02-9d2b-17d11377b1f1/Sandboxnew/WS/XXXXX/Codeunit/ImportSOFile

Body:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <ImportSO xmlns="urn:microsoft-dynamics-schemas/codeunit/ImportSOFile">
            <fromMailID_iTxt>test@test.com</fromMailID_iTxt>
            <fileName>newtest01.csv</fileName>
            <fileData_BigTxt>SCwyNDcyNTgsMTEvMTEvMjAyMSwsLCw5MzQ2Mzc2MDk....CksMSw1My44MSwwLA==</fileData_BigTxt>
        </ImportSO>
    </Body>
</Envelope>















Postman Snapshot:








Thank you for reading 

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

Tuesday, November 9, 2021

Business Central 14 On-Prime to Install Base App and Sync it than Transfer Data to Extension

 Hello Friends,

Below blog help to install base System and Application app in Converted BC 14 On-Prime DB

After we can Generate System Table Symbol and transfer data from Dummy 50K Series Table to Actual Extension Table

1)      Run Power ISE by Admin

Import the PS1 file

Import-Module 'C:\Program Files\Microsoft Dynamics 365 Business Central\140\Service\NavAdminTool.ps1'







 

Now install the System Base App and Sync it below primary steps to follow.

-          Publish

-          restart

-          Sync tenant

-          Sync App

-          Install

============

Start First with Publish App

Publish-NAVApp -ServerInstance BC140 -Path "C:\Users\navadmin\Desktop\Temp\1 - Effvision_Standard_TableExtension\.alpackages\Microsoft_System_14.0.47286.0.app" -SkipVerification 

Publish-NAVApp -ServerInstance BC140 -Path "C:\Users\navadmin\Desktop\Temp\1 - Effvision_Standard_TableExtension\.alpackages\Microsoft_Application_14.0.47286.0.app" -SkipVerification

 Restart Service

Restart-NAVServerInstance -ServerInstance BC140 

Sync Tenant 

Sync-NAVTenant -ServerInstance BC140 -Mode Sync -Tenant Default

 

Sync NAVApp 

Sync-NAVApp -ServerInstance BC140 -Tenant Default -Name "System" -Version 14.0.47286.0 

Sync-NAVApp -ServerInstance BC140 -Tenant Default -Name "Application" -Version 14.0.47286.0

 

Install NAVApp 

Install-NAVApp -ServerInstance BC140 -Tenant Default -Name "System" -Version 14.0.47286.0  

Install-NAVApp -ServerInstance BC140 -Tenant Default -Name "Application" -Version 14.0.47286.0  

===================

Now you can generate table symbol for upgrade


After you can publish your developer BC Extension with Table Extension and Custome Table

Once you publish primary exte



NAV 2016 - Save Image Blob File on Server - Convert from Base 64

 Hello Friends,

Today we received request from client to save the image to server folder from base 64 image string (it will call from powerapp using NAV web service)

Below function we create for development

---------------------------------------------------

    PROCEDURE SaveDocumentImage_gFnc@33027920(DocNo_iCod@33027921 : Code[20];Image_Base64_iBigTxt@33027931 : BigText) : Boolean;

    VAR

      PurchaseHeader_lRec@33027929 : Record 38;

      RecordLink_lRec@33027920 : Record 2000000068;

      FoundRecID_lRecID@33027922 : RecordID;

      FileSaveLocalFolderFullpath_lTxt@33027923 : Text;

      FileGloabalURLPath_lTxt@33027924 : Text;

      NameofFile_lTxt@33027925 : Text;

      Bytes@33027930 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array";

      Convert@33027928 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Convert";

      MemoryStream@33027927 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream";

      OStream@33027926 : OutStream;

      TempBlob@33027932 : Record 99008535;

      IStream@33027933 : InStream;

      GLSetup_lRec@33027934 : Record 98;

      FileManagement_lCdu@33027935 : Codeunit 419;

    BEGIN

      IF DocNo_iCod = '' THEN

        ERROR('DCNo_iCod cannot be blank');


      IF FORMAT(Image_Base64_iBigTxt) = '' THEN

        ERROR('Image_Base64_iBigTxt cannot be blank');


      GLSetup_lRec.GET;

      GLSetup_lRec.TESTFIELD("Server Att Local Folder Path");

      GLSetup_lRec.TESTFIELD("Server Web Global URL for Att");


      NameofFile_lTxt := FORMAT(CURRENTDATETIME,0,'<Day,2>_<Month,2>_<Year4>_<Hours24>_<Minutes,2>_<Seconds,2>') +'_'+ FORMAT(RANDOM(100)) + '.jpg';

      FileSaveLocalFolderFullpath_lTxt := GLSetup_lRec."Server Att Local Folder Path" + NameofFile_lTxt;

      FileGloabalURLPath_lTxt := GLSetup_lRec."Server Web Global URL for Att" + NameofFile_lTxt;


      PurchaseHeader_lRec.GET(PurchaseHeader_lRec."Document Type"::Order,DocNo_iCod);

      FoundRecID_lRecID := PurchaseHeader_lRec.RECORDID;


      Bytes := Convert.FromBase64String(Image_Base64_iBigTxt);

      MemoryStream := MemoryStream.MemoryStream(Bytes);

      TempBlob.Blob.CREATEOUTSTREAM(OStream);

      TempBlob.Blob.CREATEINSTREAM(IStream);

      MemoryStream.WriteTo(OStream);


      FileManagement_lCdu.BLOBExportToServerFile(TempBlob,FileSaveLocalFolderFullpath_lTxt);


      //SaveImageAttachment_lFnc(Image_Base64_iBigTxt,GateEntryHeader_lRec);


      CLEAR(RecordLink_lRec);

      RecordLink_lRec.INIT;

      RecordLink_lRec."Record ID" := FoundRecID_lRecID;

      RecordLink_lRec.URL1 := FileGloabalURLPath_lTxt;

      RecordLink_lRec.Description := NameofFile_lTxt;

      RecordLink_lRec.Company := COMPANYNAME;

      RecordLink_lRec."User ID" := USERID;

      RecordLink_lRec.Created := CURRENTDATETIME;

      RecordLink_lRec.Type := RecordLink_lRec.Type::Link;

      RecordLink_lRec.INSERT;

      COMMIT;


      EXIT(TRUE);

    END;


==============