Tag Archives: d365 fins and ops development

Print QR Code With Logo In X++ & Microsoft Dynamics 365 for finance and operations.

Hello Folks, today I am sharing you the standard way to point QR code with Logo in X++.

System.Drawing.Bitmap   icon;
EFDocQRCode_BR          generateQR = new EFDocQRCode_BR();

icon = new System.Drawing.Bitmap("K:\Logo\MyLogo.bmp");
generateQR = new EFDocQRCode_BR();
generateQR.parmIcon(icon);
generateQR.parmIconRatio(0.25);

return generateQR.generateQRCode("www.google.com");

This code will return you a container which can be use directly in image control inside a SSRS report or in an ER report format

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 –

System.Drawing.Bitmap
System.Drawing.Image
System.Drawing.Graphics
System.Drawing.Imaging.ImageFormat
System.Drawing.Color

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.Clear(System.Drawing.Color::Black);
g.DrawImage(img1, new Point(0, 0));
g.DrawImage(img2, new Point(img1.Width, 0));

g.Dispose();
img1.Dispose();
img2.Dispose();

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

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

[DataContract]
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();
contract.initialize(_vendInvoiceJour);
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

[BusinessEvents(classStr(PAAPurchInvoiceJournalPostBusinessEventContract),
“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();

businessEvent.parmVendInvoiceJour(_vendInvoiceJour);
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

if(BusinessEventsConfigurationReader::isBusinessEventEnabled(classStr(PAAPurchInvoiceJournalPostBusinessEvent)))
{
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; 
        if(filterformDataSource)
        {
            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 FO – Generate next Number sequence in X++ using NumberSeq Class

Requirement – D365 FO – GENERATE NEXT NUMBER SEQUENCE IN X++ USING NUMBERSEQ CLASS

Continue reading D365 FO – Generate next Number sequence in X++ using NumberSeq Class

‘RunAs’ function & method in Dynamics 365 Finance & Operations

Introduction:

There are some scenarios in Microsoft Dynamics 365 finance and operations where we need to run X++ program or code or business operation on the behalf of different userId other than current userId.

In my case, my X++ program of D365 finance and operations should always run under the userId- ADMIN . I can use ‘RunAs’ function & method in Dynamics 365 Finance & Operations.

Sample Code:

class AcxSharepointIntegeration
{
    public static container download(container _parms)
    {
        RunAsPermission perm;
        perm = new RunAsPermission("Admin");
        perm.assert();
        Container returncontainer = runAs("Admin", classnum(AcxSharepointIntegeration), "get", _parms);
        CodeAccessPermission::revertAssert();
        return returncontainer;
    }

    public static container get(container _parms)
    {
        container con;
        // Your business Logic
        return   con; 
    }

class AcxSharepointIntegeration
{
public static container download(container _parms)
{
RunAsPermission perm;
perm = new RunAsPermission(“Admin”);
perm.assert();
Container returncontainer = runAs(“Admin”, classnum(AcxSharepointIntegeration), “get”, _parms);
CodeAccessPermission::revertAssert();
return returncontainer;
}

public static container get(container _parms)
{
container con;
// Your business Logic
return con;
}

D365 FO : SQL Connection & Access of production environment Using X++

  • Introduction – In earlier version of Microsoft Dynamics AX, Customer and partner had full control and access of Microsoft SQL Server and they were able to connect to Microsoft SQL Server of production server.Customer and partner were also able to use SSMS (SQL Server Management Server) in Microsoft Dynamics AX Production for querying and executing direct SQL Statements in certain scenarios.
  • But In Microsoft Dynamics 365 finance and operation Cloud & SaaS (Software as a service application) model , you cannot connect to Microsoft SQL server of production and you don’t have any access of production server SQL.
  • Only Microsoft has full control of production servers and responsible for tasks like maintenance, backups etc.
  • Customer is using LCS (Life cycle services) for deployments, service upgrades etc.
  • It is not recommend to execute direct SQL statement in SQL server of production but still in certain scenarios we need it.
  • Steps to connect SQL server of Microsoft Dynamics finance and operations production environment and executing SQL statements directly using X++
  • In this example, login to visual studio and create a runnable class in Microsoft D365 finance & operations.

  • Write the below code, for SQL update and delete command execution in production server SQL database.
  • Above piece of code works just fine when you are executing SQL update or delete statements or commands. But in some scenarios, we have to use SQL select commands or statements directly in production SQL.
  • In below screenshot and code i am showing how can we execute direct SQL statement and command.
  • The difference bewtween update/delete & select sql statement is that in select i am using method statement.executeQuery(sqlStr) whereas in update/delete SQL statement i am using statement.executeUpdate(sqlStr).
  • In this way we can execute SQL update, delete, select etc statements and commands in the production SQL database of Microsoft dynamics 365 finance and operations using X++.
  • Also read my post on D365/AX7:Connect To An External SQL Database Using X++.

D365 FO/AX7/Class Extension: COC (Chain of command) & Method Wrapping With Example

  • Introduction COC (chain of command) & Method Wrapping In Microsoft Dynamics 365 finance and operations –
  • Microsoft D365 Finance and operations supports very powerful feature called COC or method wrapping.
  • In past, Microsoft Dynamics AX/Axapta supports overlayering where you can overlayer Microsoft classes, table methods etc directly by placing your code in the middle, bottom or top if standard code. Below is screenshot and example for your reference. In below screenshot i placed my custom code in the middle of standard method by using overlayering.
  • In Microsoft Dynamics 365 finance and operations (After version 8.0) , you cannot overlayer code as everything is sealed now. We have to use COC or method wrapping.Microsoft has improved the Functionality of Class extension for D365 FO by adding wrap logic around methods which are defined in the base class that you are augmenting. You can Wrap or do Chain of command (COC) of public and protected methods.
  • In below screenshot i am using method wrapping or class extension of standard class which is different from Microsoft Dynamics AX overlayering approach.

  • Next keyword means to call the orginal method “ChecItemPostingDate” of standard class “InventUpdate”
  • You can get values of Global Variables of in your extension class of your parent class or main class.
  • Final Modifier means The method can’t be overridden in any class that derives from its class.
  • Here are one more example where we are using COC (chain of commands) in Table methods.

Benefits Of Using Change Of Commands instead of Old Overlayering approach in Microsoft Dynamics 365 finance and operations

  1. Easy Future upgrades and version enhancements as you are not doing overlayering in standard classes or methods or objects & keeping you separate extension classes.
  2. Neat & Clean development as no need to compile whole code librarary.