Tag Archives: Microsoft Dynamics 365 finance and operations

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.

Archive inventory transactions (Purge InventTrans) in Microsoft Dynamics 365 for finance and operations

As we know, “InventTrans” table is one of the largest table in Microsoft D365 for finance and operations and this table keep growing through out the ERP lifecycle and consume more space. BUT ! here is the good news that Microsoft has released a standard feature and a standard batch job to archive inventory transactions and purge InventTrans table data.

Here is the Microsoft document link – https://docs.microsoft.com/en-us/dynamics365/supply-chain/inventory/archive-inventory-transactions

cheers,

Piyush Adhikari

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(
            zipArchiveStream,
            System.IO.Compression.ZipArchiveMode::Create,
            true))
        {
            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);
                    fileStream.CopyTo(fileEntryStream);
                }
            }

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

}

Upload & Read JSON File from Local Folder

Breaking Changes in ArduinoJson 6.0 - Wia Community

Requirement:

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:JSON Creation & SERIALIZATION Using FormJsonSerializer & X++

Requirement

SON CREATION & SERIALIZATION USING FORMJSONSERIALIZER & X++ in Microsoft Dynamics 365 for finance and operations.

Format Of Output JSON String & Message

{"itemCategory":123456,"itemClassification":"A","itemCode":"ItemXYZ","itemGroup":"ItemGroup","itemname":"ItemXYZ Name","onDate":"/Date(1597363200000)/","Optimized":"Yes","site":"SiteCode"}
Continue reading D365 FO:JSON Creation & SERIALIZATION Using FormJsonSerializer & X++

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

Entity store In Azure Data Lake – D365 FINANCE & OPERATIONS

What is Entity Store ?

In Microsoft Dynamics 365 finance and operations, Entity store is database (AxDW) which you can use in D365 FO POWER BI dashboards for realtime analytical reporting . Click here to read more about entity store.

What is Azure Data Lake ?

Microsoft Azure Data Lake is cloud based storage and analytics service . Azure Data lake allows data scientist and data engineer to store any kind of large data and performing analytics, machine learning & AI operations on it. Click here to read more about entity store.

Quick Steps Exporting Entity Store in Azure Data Lake

  • Deploy a new storage account in azure portal. Don,t forget to mention Account kind as  StorageV2. Most important, in Advance TAB Enable the Hierarchical namespaces feature else you will not be able to consume Azure Data Lake data in Power BI.
  • When the deployment is completed, go to your recently deployed storage account and navigate to Settings –> Access Keys . Note down the connection string value, it will be used in coming steps
  • Deploy a KEY VAULT resource in portal.azure.com as per your comfort.
  • After deployment of key vault , go to your Azure KEY VAULT resource and navigate to Settings — > Secrets.
  • Click on button + GENERATE/IMPORT & create a SECRET. Fill a name for the secret and not it somewhere as NAME will be used in next steps. In the VALUE Field please Enter the connection string i (connection string you obtained from previous steps inside STORAGE ACCOUNTS)
  • Secret KEY is created
  • Go to Azure portal, select Azure Active Directory, and then select App registrations. You need to register an App
  • After registering you APP, navigate to –>API permission and Configured permissions as mentioned below.
  • In your registered APP, navigate to –> Certificates & secrets. Generate a new client secret and copy it immediately somewhere.
  • Now go back to your KEY VAULT Resource and click on access polices.
  • In the Select principal field, select the name of the application that you previously registered.In the Key permissions field, select Get and List permissions.In the Secret permissions field, select Get and List permissions.
Get and List permissions
  • Now open your D365 finance and operations environment and go the SYSTEM PARAMETERS . Fill the below details
  • Application ID: Enter the application ID of the Azure AD application that you registered earlier.
  • Application Secret: Enter the application key (secret) for the Azure AD application.
  • DNS name: Enter the DNS name of Key Vault.
  • Secret name: Enter the name of the secret that you added to Key Vault together with connection string information.
  • Validate and Test AZURE KEY VAULT as well as AZURE DATA STORAGE
  • Refresh Entity Store
  • Now your entity store is available in Azure Data Lake.

References : entity-store-data-lake

Date functions snippet in D365 Finance & Operations & Microsoft Dynamics AX

  • Get maximum date : TransDate maximumDate = dateMax();
  • Get minimum date: TransDate minimumDate= datenull();
  • Get Current or today’s Date: TransDate todayDate = today();
  • Convert string to date:  TransDate transdate = str2Date(’26-06-2020′, 123);(day = 1, month = 2, year = 3)
  • Convert date to string: str dateStr = date2Str(today(), 123, DateDay::Digits2, DateSeparator::Hyphen, DateMonth::Digits2, DateSeparator::Hyphen, DateYear::Digits4, 0);
  • Convert String to datetime: utcdatetime dateTime = str2Datetime(‘26.06.2020 11:00:00 pm’, 123);
  • Get current system date time : utcdatetime currentDateTime = DateTimeUtil::getSystemDateTime();
  • Get current system date : Transdate currentDate = DateTimeUtil::getSystemDate();
  • getCompanyTimeZone = DateTimeUtil::getCompanyTimeZone();
  • getUserPreferredTimeZone = DateTimeUtil::getUserPreferredTimeZone();
  • getClientMachineTimeZone = DateTimeUtil::getClientMachineTimeZone();// get clie
  • getOriginatingTimeZone = DateTimeUtil::getOriginatingTimeZone(transDateTime); // get originating time zone
  • dateTime = DateTimeUtil::minvalue(); // get minimum value of date time
  • dateTime = DateTimeUtil::maxvalue(); // get maximum value of date time