Category Archives: X++


Combine & Merging images to a single image using X++ & C# Dot Net Libraries

How to Merge Two Brands: Successful M&A

Requirement – The requirement is to combine and merging images to a single image using X++ & C# Dot Net Libraries in Microsoft Dynamics 365 finance and operation.

Classes & Libraries –


Sample Code –

str jpg1 = @”c:\images.jpeg”;
str jpg2 = @”c:\images2.jpeg”;
str jpg3 = @”c:\image3.jpg”;

System.Drawing.Image img1 = System.Drawing.Image::FromFile(jpg1);
System.Drawing.Image img2 = System.Drawing.Image::FromFile(jpg2);

int width = img1.Width + img2.Width;
int height = System.Math::Max(img1.Height, img2.Height);

System.Drawing.Bitmap img3 = new System.Drawing.Bitmap(width, height);

System.Drawing.Graphics g = System.Drawing.Graphics::FromImage(img3);

g.DrawImage(img1, new Point(0, 0));
g.DrawImage(img2, new Point(img1.Width, 0));


img3.Save(jpg3, System.Drawing.Imaging.ImageFormat::Jpeg);

D365 FO : Developing Business Events with X++ from scratch

Microsoft Dynamics AX/D365 F&O Technical blog

Business events provide a mechanism that allow external system receives notifications from Microsoft Dynamics 365 Finance and operations. For example – When you are posting a purchase invoice then you can send notifications/ payload / message to an external system.

You can use existing standard business events which are available in the D365 FO or you can also develop and customize new business events as per your need.

There are 2 ways you can consume business events . 1. Power automate (Microsoft Flow) 2. Azure messaging services.

Scenario – In this example, I am going to show you how we can develop a new custom business event from scratch. In my scenario, business event in D365 FO should be triggered when a user is posting purchase invoice in Microsoft dynamics 365 for finance and operations.

There a 2 standard and base classes which i will use to develop custom business events –

  1. BusinessEventsContract ( Use for developing/defining payload message)
  2. BusinessEventsBase ( Use for triggering custom business event)

Create a PAAPurchInvoiceJournalPostBusinessEventContract class

class PAAPurchInvoiceJournalPostBusinessEventContract extends BusinessEventsContract
private VendAccount vendAccount;
private PurchId purchid;
private InvoiceId invoiceId;

private void initialize(VendInvoiceJour _vendInvoiceJour)
vendAccount = _vendInvoiceJour.OrderAccount;
purchid = _vendInvoiceJour.PurchId;
invoiceId = _vendInvoiceJour.InvoiceId;

public static PAAPurchInvoiceJournalPostBusinessEventContract newFromVendInvoiceJour(VendInvoiceJour _vendInvoiceJour)
PAAPurchInvoiceJournalPostBusinessEventContract contract = new PAAPurchInvoiceJournalPostBusinessEventContract();
return contract;

private void new()

[DataMember(‘VendAccount’), BusinessEventsDataMember(‘VendAccount’)]
public vendAccount parmvendAccount(vendAccount _vendAccount = vendAccount)
vendAccount = _vendAccount;
return vendAccount;

[DataMember(‘PurchId’), BusinessEventsDataMember(“PurchId”)]
public PurchId parmPurchId(PurchId _purchId = purchId)
purchId = _purchId;
return purchId;

[DataMember(‘InvoiceId’), BusinessEventsDataMember(“InvoiceId”)]
public InvoiceId parmInvoiceId(InvoiceId _invoiceId = invoiceId)
invoiceId = _invoiceId;
return invoiceId;


Create a PAAPurchInvoiceJournalPostBusinessEvent class

“Custom Vendor Invoice Post Business Event”,
“This business event is triggering during the time purchase invoice posting”,ModuleAxapta::AccountsPayable)]
class PAAPurchInvoiceJournalPostBusinessEvent extends BusinessEventsBase
private VendInvoiceJour vendInvoiceJour;

static public PAAPurchInvoiceJournalPostBusinessEvent newFromVendInvoiceJour(VendInvoiceJour _vendInvoiceJour)
PAAPurchInvoiceJournalPostBusinessEvent businessEvent = new PAAPurchInvoiceJournalPostBusinessEvent();

return businessEvent;

private VendInvoiceJour parmVendInvoiceJour(VendInvoiceJour _vendInvoiceJour = vendInvoiceJour)
vendInvoiceJour = _vendInvoiceJour;
return vendInvoiceJour;

private void new()

[Wrappable(true), Replaceable(true)]
public BusinessEventsContract buildContract()
return PAAPurchInvoiceJournalPostBusinessEventContract::newFromVendInvoiceJour(vendInvoiceJour);


you must add below block of code in purchase invoice posting routine class. Also business must be activated or enabled in that company. Business event will trigger when purchase invoice posting will take place.

VendInvoiceJour vendInvoiceJour = this; // vendInvoiceJour buffer

PAAPurchInvoiceJournalPostBusinessEvent::newFromVendInvoiceJour(this).send () ;


Build your project solution and navigate to path -[System administration–> Setup –> Business Events –> Business Events Catalog] to see and activate your business event.

D365 FO – Create deep links, shareable, secured URLs in Microsoft Dynamics 365 for finance & operations

A complete guide to mobile app deep linking | Adjust

What is deep links in Microsoft Dynamics 365 for finance and operation? Deep links are shareable and secures URLs to a specific form. Optional filters can be passed so that when user will open the deep link and navigate to a specific form then it will show filtered data ore records. In Microsoft D365 FO, below library – Microsoft.Dynamics.AX.Framework.Utilities.UrlHelper.UrlGenerator is used to generate deep links using X++ .

Sample Code – Below is the sample code of developing & generating deep links for D365 FO forms and records using filter and ranges in form data source. In below example, i am generating the sharable URL (deep link ) of a form – CustAccount and applying a “CustAccount” filter on custTable datasource.

using Microsoft.Dynamics.AX.Framework.Utilities; // setting library/Dll reference

class DeepLinkTest
    public static void main(Args _args)
        MenuItemNameDisplay menuItemName                = menuItemDisplayStr(CustTable);  // customer form
        MenuItemType        menuItemtype                = MenuItemType::Display;
        str                 filterformDataSource        = formDataSourceStr(CustTable, CustTable);  // filer datasource
        str                 filterFormDataSourceField   = fieldStr(CustTable, AccountNum); // filter field

        UrlHelper.UrlGenerator generator = new UrlHelper.UrlGenerator();
        System.Uri currentHost = new System.Uri(UrlUtility::getUrl());
        generator.HostUrl = currentHost.GetLeftPart(System.UriPartial::Authority);
        generator.Company = curExt();
        generator.MenuItemName = menuItemName;
        generator.MenuItemType = menuItemtype;
        generator.Partition = getCurrentPartition();
        generator.EncryptRequestQuery = true; 
            UrlHelper.RequestQueryParameterCollection requestQueryParameterCollection;
            requestQueryParameterCollection = generator.RequestQueryParameterCollection;
            requestQueryParameterCollection.UpdateOrAddEntry(filterformDataSource, filterFormDataSourceField, "CustAccount"); // applying filter

        System.Uri fullURI = generator.GenerateFullUrl();
        Info(fullURI.AbsoluteUri); // getting deep link


D365 Fin & Ops : ZIP, Compress & Archive multiple files using X++ & class ZipArchiveEntry

Requirement : The requirement is to create a zip file from a set of document entries available in document handling, creating a download link and sends the link to user browser.

In this requirement we are using Microsoft Dynamics 365 for finance and operations classes – documentmanagement, ziparchive & ziparchiveentry.

Sample Code :

class RunnableClassZIP
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
        System.IO.Stream fileStream;
        System.IO.MemoryStream zipArchiveStream = new System.IO.MemoryStream();
        DocuRef docuRef;
        DocuValue docuValue;
        const str extensionZip = '.zip';
        const str zipFileName = 'myZipfile';
        using (System.IO.Compression.ZipArchive zipArchive = new System.IO.Compression.ZipArchive(
            while select docuRef
                join docuValue
            where docuValue.RecId   == docuRef.ValueRecId
            && docuRef.RefTableId   == 'your table id'
            && docuRef.RefRecId     == 'your rec id'
                // Creates the file entry in the zip folder.
                System.IO.Compression.ZipArchiveEntry fileEntry = zipArchive.CreateEntry(docuValue.filename());
                // Opens the created file entry and copies the binary file information of the original file to the file entry in the zip folder.
                using (System.IO.Stream fileEntryStream = fileEntry.Open())
                    // Gets the file stream of the document attachment.
                    fileStream = DocumentManagement::getAttachmentStream(docuRef);

            // Send a download link of the created zip folder to the user.
            File::SendFileToUser(zipArchiveStream, zipFileName + extensionZip);



Hey Folks ! I had a requirement in Microsoft Dynamics 365 for finance and operations where I want to save & download a file from a SHAREPOINT site and from its folder using X++ code. Here i am using classes –


D365/AX7:Upload & Save a File in Azure Blob Storage using X++

Using Azure Blob Storage In Scheduled Tasks | Notificare

Requirement: Saving a file and uploading memory stream of file in Azure BLOB Storage account using X++ in Microsoft Dynamics 365 finance and operations

Continue reading D365/AX7:Upload & Save a File in Azure Blob Storage using X++

D365/AX7: Read & Download a File from Azure Blob Storage Using X++

Part-1: Azure BLOB storage with Dynamics 365 for operations

Requirement – Reading a file & getting the memory stream of file from Azure Blob Storage in Microsoft dynamics 365 for finance and operations using X++.

Upload & Read JSON File from Local Folder

Breaking Changes in ArduinoJson 6.0 - Wia Community


Customer has saved some JSON files in local folder of laptop or server or drive. Customer wants upload the JSON files from local drive to microsoft Dynamics 365 finance and operations for further business process. A dialog will open in Microsoft D365 fin & ops, customer will select JSON files and import.

Continue reading Upload & Read JSON File from Local Folder

D365 FO:Catch exceptions & Inner exceptions thrown from CLR objects Using ClrInterop & X++

Exception Handling in Java | Java Exceptions - javatpoint

In Microsoft Dynamics 365 for finance and operations, when you use .Net assemblies or classes it is important that you code should handle & capture & catch all the .Net inner exceptions.

D365 FO : Printing & Generate QR code in SSRS Report

Requirement – PRINTING & GENERATE QR CODE IN SSRS REPORT USING MICROSOFT.DYNAMICS.QRCODE.ENCODER & X++ in Microsoft Dynamics 365 finance and operations.

Continue reading D365 FO : Printing & Generate QR code in SSRS Report