Friday 10 May 2024

How to Convert Images to Base64 Strings in D365 Finance & Operations

In this blog, I will discuss how to convert an image into a base64 encoded string in Dynamics 365 Finance and Operations (D365FO). Fortunately, D365FO provides a built-in class, BinData, equipped with a method that returns a base64 encoded string. Below, I have provided a block of code that demonstrates how to accomplish this task.

Explanation of the Source Code:

  1. Initialize and Declare the BinData Class: First, create an instance of the BinData class, which will be used to handle the binary data of the image.

  2. Retrieve the Image from a Worker: Obtain the image file associated with a worker. This image is typically stored as a binary file or blob in the database.
  3. Pass the Image to setData() Method: Load the image data into the BinData instance using the setData() method. This method prepares the image data for conversion by handling it as binary data.

  4. Convert to Base64 Encoded String: Use the base64Encode() method of the BinData class to convert the binary data of the image into a base64 encoded string. This string can then be used in HTML, stored, or transmitted as needed.























That is it. Thanks.

Tuesday 7 May 2024

Creating and Consuming a .Net Library for SFTP Connection in Dynamics 365 Finance & Operations (Part-1)

Introduction

In today's interconnected systems, secure file transfers are critical. SFTP (Secure File Transfer Protocol), which utilizes SSH (Secure Shell) for enhanced security, is commonly used for this purpose. In this blog, I will guide you through creating a .Net library to establish an SFTP connection and demonstrate how to integrate this library into a Dynamics 365 Finance & Operations (D365FO) environment.

Step 1: Create a .Net Class Library

First, start by creating a .Net class library. This library will be responsible for handling the SFTP connection.

Step 2: Add Necessary NuGet Packages

For handling SFTP operations, add the following packages to your project:

  • Renci.SshNet – Provides the basic functionality for SFTP connections.
  • Microsoft.Bcl.AsyncInterfaces – Required for async support in .Net Standard 2.0 projects.

Note: You can install these packages via NuGet Package Manager or using the Package Manager Console.

Step 3: Implement SFTP Connection Logic

Implement the SFTP connection logic within your library. Create methods for connecting to the SFTP server, as well as for listing directories, downloading, and moving files.














Use the following code snippet for Getting directory, files and moves them after executing in the related folder.












Step 4: Build and Deploy the Library

After implementing the necessary functionality in your .Net library, build the project. Navigate to the bin\Debug or bin\Release folder, depending on your build configuration, and locate the generated DLLs. Select the highlighted DLLs from .Net project as shown below.



Step 5: Integrate with Dynamics 365 FO

To use your new library within Dynamics 365 FO, you need to import the DLLs into your project. Copy the DLLs from your .Net project's output folder to the AOSService->PackageLocalDirectory->Your Model Bin folder of your AX extension. This makes the library available to your AX project.








Step 6: Consume the Library in D365FO

Now, you can invoke the methods from your SFTP library within your D365FO codebase. You might need to handle any threading considerations, depending on how D365FO consumes external libraries.








Conclusion

By following these steps, you have created a reusable .Net library capable of handling SFTP operations and integrated it within Dynamics 365 FO, enhancing your application’s ability to interact securely with external systems through file transfers. This integration not only secures data transmission but also extends the functionality of your D365FO environment efficiently.

Saturday 4 May 2024

Fetching GST Amount from CustInvoiceLine in X++ D365 F&O

Recently, I was tasked with displaying the GST amount for a free text invoice. In my source code at the backend, I only had access to the CustInvoiceLine Table, while the GST amounts are stored in the TaxTrans Table. Initially, I struggled to find a direct relationship between these two tables, as multiple tables are needed to establish a relation. However, after some research, I discovered that the CustInvoiceLine already has an out-of-the-box method displayTaxAmount() which returns the GST amount.

Please see the screenshot below for more details.




How to Convert Images to Base64 Strings in D365 Finance & Operations

In this blog, I will discuss how to convert an image into a base64 encoded string in Dynamics 365 Finance and Operations (D365FO). Fortunate...