Translate

Wednesday, June 11, 2025

Converting a System.IO.MemoryStream object to Image in Dynamics 365 Finance and Operations using x++

๐Ÿ“˜ Introduction

In Dynamics 365 Finance and Operations (D365FO), it's common to deal with external systems returning image streams, such as a barcode service, a document API, or a file server. In such cases, you may receive the image as a binary stream (System.IO.Stream), You’ll need to convert it into a container to display it in the UI or store it in the database.

This blog post explains how to convert a MemoryStream into a displayable image in D365FO using X++.

๐Ÿงช Sample Scenario

Let’s say you're calling an external URL using System.Net.HttpWebRequest and want to load the image from the response into a form control.

✅ X++ Code to Convert MemoryStream to Image

System.Net.HttpWebRequest request = System.Net.WebRequest::Create("https://example.com/sample-image.png") as System.Net.HttpWebRequest;

System.Net.HttpWebResponse response;
System.IO.Stream stream;
System.IO.MemoryStream fileStream = new System.IO.MemoryStream();

request.Method = "GET";
request.ContentType = "image/png";

response = request.GetResponse() as System.Net.HttpWebResponse;

using (response)
{
    stream = response.GetResponseStream();

    // Convert the stream into a memory stream
    stream.CopyTo(fileStream);

    // Convert memory stream to container
    BinData binData = new BinData();
    container baseContainer = Binary::constructFromMemoryStream(fileStream).getContainer();
    Image image = new Image();

     // Set container data to BinData
    binData.setData(baseContainer);

    // Set image data
    image.setData(binData.getData());

     // Display in image control (e.g., FormImageControl1)
    FormImageControl1.image(image);
}


๐Ÿ’ฌ Explanation

  • HttpWebRequest is used to call the external image URL.

  • ✅ The response stream is copied into a MemoryStream.

  • ✅ We use Binary::constructFromMemoryStream() to convert the stream into a container.

  • ✅ This container is then used to create an Image object.

  • ✅ Finally, we bind it to the form’s image control like FormImageControl1.

๐Ÿ’ก Use Case Ideas

  • Show customer logos dynamically.

  • Load barcode images from external services.

  • Display product thumbnails received via APIs.

๐Ÿง  Conclusion

Working with external image streams in D365FO using X++ becomes seamless when you properly convert the stream into a container and use BinData + Image objects. This approach is ideal for real-time image rendering from REST APIs or streaming sources.


๐Ÿงฉ What is Microsoft Power Platform and Can It Be Used in D365 Finance and Operations?

๐Ÿ” Introduction
In the world of enterprise solutions, agility and automation are key. Microsoft Power Platform is a powerful suite of tools that complements Dynamics 365 Finance and Operations (D365 F&O) to help streamline business processes, build apps quickly, and gain actionable insights — all with minimal coding.

⚙️ What is Microsoft Power Platform?

Microsoft Power Platform is a collection of low-code/no-code tools that help users analyse data, automate workflows, and build custom apps or chatbots. 

 It consists of the following four core components:

  1. Power BI:

    A powerful business analytics tool that allows users to visualise and analyse data. With Power BI, you can create interactive reports and dashboards to make data-driven decisions. It connects to multiple data sources, including cloud-based and on-premises databases.

  2. Power Apps:

    A platform for creating custom applications with minimal coding. Power Apps enables users to build applications tailored to their specific needs, whether for mobile, desktop, or web. It’s useful for automating tasks, managing data, and interacting with business systems like Dynamics 365.

  3. Power Automate:

    A tool to automate repetitive tasks and workflows. With Power Automate, you can create workflows that connect various applications and services. It allows businesses to automate processes like approvals, notifications, data collection, and task management, saving time and reducing human error.

  4. Power Virtual Agents:

    A platform for building intelligent chatbots without writing code. These chatbots can assist users in answering questions, guiding them through workflows, and automating customer support tasks. Power Virtual Agents integrates easily with other parts of the Power Platform and business systems.

    Key Benefits of Power Platform:

    • Low-Code/No-Code: Allows both technical and non-technical users to build solutions.
    • Automation: Helps automate repetitive tasks, improving efficiency and productivity.
    • Integration: Seamlessly integrates with Microsoft products like Dynamics 365, SharePoint, and Azure, as well as third-party services.
    • Custom Solutions: Allows businesses to create tailored applications and workflows without needing a developer.

๐Ÿ’ก Power Platform Can Be Used with D365 Finance and Operations

Microsoft Power Platform can be integrated directly with Dynamics 365 Finance and Operations (D365 F&O) to enhance functionality, streamline workflows, and provide greater business intelligence. Below is a detailed breakdown of how each Power Platform tool can be integrated with D365 F&O:

1. Power BI and D365 F&O Integration

Power BI can be used with D365 F&O to deliver powerful business analytics and visualisations. The integration helps you analyse real-time data, create interactive reports, and build dashboards that are easy to interpret.

How Power BI Integrates:

  • Embedded Reports and Dashboards: You can embed Power BI reports and dashboards directly into D365 F&O interfaces. This allows you to display key metrics, KPIs, and data insights within the same platform, offering users a seamless experience.
  • Data Connections: Power BI can connect directly to D365 F&O’s data entities via OData (Open Data Protocol). This enables pulling data from tables like sales orders, inventory, financial transactions, etc., and analysing it in real-time.
  • Pre-built Content: Microsoft provides pre-built Power BI content packs for D365 F&O, which are ready-made reports that can be used for common analytics like financial performance, inventory levels, or order fulfilment.

Benefits:

  • Real-time reporting and data visualisation.
  • Decision-makers can make data-driven choices based on the latest information.
  • Visualise large amounts of data in an accessible way.

2. Power Apps and D365 F&O Integration

Power Apps allows you to build custom applications that interact with D365 F&O data. These applications can range from simple mobile apps to complex enterprise-level solutions, depending on the requirements.

How Power Apps Integrates:

  • Custom Apps: You can create custom Power Apps that pull and push data from D365 F&O. For example, you can build apps for sales teams to track customer orders or for employees to submit expense reports.
  • Data Entities: Power Apps can interact with D365 F&O via Data Entities (predefined structures that represent D365 F&O data). Data entities expose information from D365 F&O, making it easier to use that data in Power Apps.
  • Dynamics 365 Connectors: Microsoft provides out-of-the-box connectors that allow Power Apps to connect directly to Dynamics 365 applications, including F&O. This simplifies the process of interacting with D365 F&O data.
  • Common Data Service (Dataverse): If you're using Microsoft Dataverse (formerly Common Data Service), it can act as a unified data store that bridges Power Apps and D365 F&O. Data from D365 F&O can be stored in Dataverse, and apps can pull data from there.

Benefits:

  • Custom applications for different business processes (e.g., mobile apps for field service or inventory tracking).
  • Real-time data integration with D365 F&O for more efficient business operations.
  • No extensive coding required, making it accessible to non-developers.

3. Power Automate and D365 F&O Integration

Power Automate is a tool for automating workflows and tasks. It can integrate directly with D365 F&O to automate repetitive tasks, streamline processes, and integrate with other applications and services.

How Power Automate Integrates:

  • Automated Workflows: Power Automate can trigger workflows based on events in D365 F&O, such as when a sales order is placed, when inventory levels drop below a certain threshold, or when a financial transaction is recorded. For example, an automated workflow could send a notification to the purchasing team when an inventory item is low.
  • Connectors: Power Automate has pre-built connectors for D365 F&O, making it easy to integrate and automate processes without requiring custom development. These connectors allow actions like creating new records, updating data, or triggering alerts.
  • Cross-Application Workflows: Power Automate can also automate workflows that span multiple systems. For example, you can trigger a workflow to update customer information in both D365 F&O and Microsoft Dynamics 365 Customer Service, or automate approval processes between D365 F&O and Office 365.

Benefits:

  • Streamlined operations by automating manual tasks.
  • Integration with external systems and apps beyond D365 F&O, such as email, SharePoint, and third-party services.
  • Time-saving and reduced human error by automating routine tasks like approval workflows, notifications, and data updates.

4. Power Virtual Agents and D365 F&O Integration

Power Virtual Agents is a tool for building intelligent chatbots that can assist users with various tasks. These bots can be integrated with D365 F&O to automate customer service, help employees navigate business processes, or provide data insights.

How Power Virtual Agents Integrates:

  • Chatbots for Customer Support: A chatbot can be created to answer frequently asked questions about D365 F&O processes, such as checking inventory, retrieving order statuses, or explaining financial reports. The bot can query data directly from D365 F&O using APIs or Power Automate connectors.
  • Internal Assistance: Chatbots can also assist internal users, such as employees looking for information about company processes, financial data, or production statuses. A chatbot can help guide users through workflows, such as submitting purchase requests or tracking shipment statuses.
  • Integration with Power Automate: Power Virtual Agents can trigger workflows created in Power Automate. For example, when a user asks the chatbot to check the inventory level of a product, the bot can use Power Automate to fetch the data from D365 F&O and return the result to the user.
  • Integration with D365 Data: Through APIs or Dataverse, chatbots can pull real-time data from D365 F&O to provide users with the most up-to-date information.

Benefits:

  • Enhanced customer experience with 24/7 chatbot support.
  • Improved employee productivity with a bot that can guide users through internal processes.
  • Reduced manual intervention for routine queries and tasks.

Summary of Key Integrations:

  • Power BI: Pulls data from D365 F&O for reporting and analysis.
  • Power Apps: Allows users to create custom apps that interact with D365 F&O data for specific tasks like order tracking or expense management.
  • Power Automate: Automates workflows and tasks within D365 F&O and connects to other systems to streamline processes.
  • Power Virtual Agents: Creates intelligent chatbots that interact with D365 F&O data to assist users with queries or tasks.

By integrating Power Platform tools with D365 F&O, businesses can increase operational efficiency, automate workflows, make data-driven decisions, and enhance user experiences both internally and externally.

Key Benefits of Using Power Platform with D365 F&O:

  • Customisation: Tailor D365 F&O functionality to specific business needs without requiring extensive development expertise.
  • Automation: Streamline business processes and reduce manual work through automated workflows.
  • Data-Driven Insights: Leverage Power BI for advanced data visualisation and real-time business analytics.
  • Enhanced User Experience: Use Power Apps to create user-friendly applications, improving workflow efficiency.
  • Seamless Integration: Power Platform integrates seamlessly with D365 F&O, enhancing the overall Microsoft ecosystem.
In summary, Power Platform significantly enhances the capabilities of D365 F&O, providing users with tools to automate processes, build custom applications, generate powerful insights, and create intelligent agents.

๐Ÿ› ️ Technical Considerations

Authentication: Use Azure AD app registrations.
Performance: Be mindful when connecting to F&O via OData – it’s not optimised for heavy data loads.
Licensing: Power Platform licenses may be needed beyond D365 licenses.

Monday, May 19, 2025

How to integrate with Dynamics 365 Finance and Operations Part -3

 

7️⃣ Bring Your Own Database (BYOD)

Let's you export D365 FO data to your own Azure SQL database.

BYOD allows you to export entity data to a user created SQL Server database instead of the Entity store AXDW, which is currently not allowed to be accessed by end users in production environments. Using BYOD you can export D365FO data entities to your database manually or with batch update or change tracking options using the standard DMF export projects page. To start using BYOD, you need to configure your SQL Server database in the “Data management” workspace “Configure Entity export to database” tile:
Then you can use the Publish button to create SQL tables for selected data entities in the target database. After these steps are completed, you can export the data to your SQL database using DMF export jobs and selecting your BYOD SQL Database from the list as a target.

Key Features of BYOD:

  1. Custom Reporting:

    • Use tools like Power BI, SSRS, Excel, or third-party apps to run reports directly on exported data.

  2. Azure SQL Support:

    • Exported data lands in a customer-provisioned Azure SQL Database, enabling flexible access.

  3. Data Entities:

    • Uses data entities to define the structure and scope of the data being exported.

  4. Incremental Push:

    • Supports full or incremental data push, minimizing data transfer and improving performance.

  5. Scheduled or Manual Exports:

    • Data exports can be triggered manually or on a schedule using batch jobs.

๐Ÿ› ️ How to Configure BYOD:

  1. Provision Azure SQL Database

    • Create a SQL Database in Azure (with appropriate firewall and access configurations).

  2. Register Database in D365FO

    • Go to Data Management > Bring your own database.

    • Register and validate your Azure SQL connection.

  3. Publish Data Entities

    • Choose the data entities you wish to export and publish them to the registered BYOD.

  4. Export Projects

    • Create and configure data export projects to schedule exports to BYOD.

๐Ÿ” Security and Access:

  • Use read-only access to the BYOD database for reporting purposes.

  • Be cautious with sensitive or PII dataensure your access model complies with your organisation's security policies.

⚠️ Limitations and Considerations:

  • No automatic schema updates: If you update a data entity in D365FO, you must republish it to BYOD.

  • BYOD is read-only; no reverse synchronisation to D365FO.

  • Does not support all entities (especially non-persisted or virtual entities).

  • Consider Export to Data Lake a modern alternative for large datasets or near-real-time scenarios.

  • Use case: Full control over data for downstream apps or reporting.

  • Setup: Define entities to export via the data management framework.

✅ Ideal for complex BI environments or legacy system syncs.

8️⃣ Azure Data Lake

With the Export to Data Lake feature, D365 FO continuously exports data entities to Azure Data Lake Gen2.

A feature still in public preview, Azure data lake publishing provides a more practical, cheaper and faster storage option for your big analytical and integration databases, which you used to access using Entity store or BYOD options before. It can publish data from entity store, data entities and standard FO tables to a “Data Lake Storage Gen2” storage, in a “near real-time” speed using the new D365FO “Data feed service”. This new data feed service works faster and saves you the hassle of maintaining DMF export jobs and batches.

Publishing your data into a data lake storage brings many benefits. It costs much less to store data in a Data Lake compared to a SQL Server data space in Azure. Plus data lake allows you to combine your FO data with data from other applications, and also CDS inside the same data lake space and run consolidated reports with them. Data lake supports Common Data Model folder structure, which can be understood by many Cloud applications and services, and it is also possible to move the data from and to CDS using CDS Data lake integrations. Usage of Azure data transformation tools like Azure Data Factory is also possible.

All in all, it brings you a couple of steps closer to Azure cloud integration and provides you with the future-proof “near-real-time” data synchronisation.

At the time of writing, Azure data lake options are still in public preview and need to be enabled from the D365FO “Feature management” window first. Then you will be able to choose tables to be published to the data lake from the “Export to Data Lake” form and push the Entity Store to the Azure data lake from the Entity Store window:

Advantages of Azure Data Lake with D365FO

AdvantageDescription
Near Real-Time Data ExportAutomatically syncs entity data to Data Lake with minimal delay—ideal for up-to-date reporting.
No Need to Republish EntitiesUnlike BYOD, you don’t need to republish when the data model changes—auto-handled by the platform.
Scalable StorageCan handle petabytes of data efficiently; no size restrictions.
Open Data FormatStores data in open formats (CSV/Parquet), which are supported by most analytics tools.
Advanced Analytics ReadyEasily connects with tools like Power BI, Azure Synapse, Databricks, and Azure ML.
Better PerformanceOffloads heavy reporting from the D365FO database, improving overall performance.
Secure & CompliantUses Azure security, RBAC, and encryption; suitable for enterprise-grade deployments.

Disadvantages of Azure Data Lake with D365FO

DisadvantageDescription
Read-Only DataYou cannot write back to D365FO—one-way export only.
Initial Setup ComplexityRequires coordination between the D365FO team and the Azure team (security, firewall, permissions).
Azure Knowledge RequiredYou need a basic understanding of Azure Storage, IAM, Synapse, etc., for effective usage.
No Ad-Hoc SQL QueriesUnlike BYOD (Azure SQL DB), you can’t directly query using SSMS or ad-hoc SQL.
First-Time Sync DelayInitial sync of large volumes can take time, especially in Production environments.
Custom Entity Support Limited (Initially)Only selected entities are available out-of-the-box; custom entities require extra setup or a workaround.
  • Use case: Big data analytics, integration with Synapse or custom data lakes.

  • Architecture: Fully managed and scalable.

✅ Best for enterprise-scale analytics and centralised data platforms.

9️⃣ Dual Write

A near-real-time bi-directional sync between D365 FO and Dataverse (Power Platform).

Dual-write is a real-time, bi-directional integration between Dynamics 365 Finance and Operations (D365FO) and Dataverse (Power Platform + CE apps like Sales, Customer Service, etc.).

It provides seamless data synchronisation so that records created or updated in one app (e.g., FO) automatically reflect in the other (e.g., CE), and vice versa, without the need for custom integrations or data sync jobs.

๐Ÿงฉ Key Concepts

FeatureDescription
Entity MappingMaps D365FO tables (data entities) with Dataverse tables (entities).
Real-time SyncUpdates flow instantly between systems.
Out-of-the-box TemplatesMicrosoft provides prebuilt mappings for common entities (Customer, Vendor, Product, etc.).
Custom Entity SupportYou can define custom mappings for custom tables/entities.
Power Platform IntegrationEnables usage of Power Apps, Power Automate, AI Builder with FO data.

Advantages of Dual-write

AdvantageDescription
Real-time Data FlowAny change in D365FO or Dataverse reflects instantly in the other system.
No Need for Manual IntegrationEliminates need for custom middleware or ETL tools between CE and FO.
Unified User ExperienceSales, Finance, and Operations users work with one version of truth.
Tight Integration with Power PlatformUse FO data in Power Apps, Power Automate, AI Builder, etc.
Prebuilt TemplatesMicrosoft provides more than 30 ready-to-use mappings to speed up setup.
Custom MappingsSupports extensibility for ISVs and partners.
Error Handling UIErrors are logged with detailed traceability in the UI with retries and fixes.

Disadvantages of Dual-write

DisadvantageDescription
Initial Setup is ComplexRequires careful setup and validation, especially in large or customised implementations.
Performance OverheadReal-time sync can cause latency or impact performance if not managed properly.
Customization ConflictsCustomisations in FO or CE can break mappings or cause sync issues.
Tightly Coupled SystemsHigh dependency between FO and Dataverse can become a risk during updates or outages.
Monitoring and MaintenanceRequires regular monitoring, handling sync failures, and managing error logs.
Limited Offline CapabilityDual-write only works when both systems are online and reachable.

๐Ÿ—️ Typical Use Cases

  • Sales to Cash Integration
    Customer data entered in Dynamics 365 Sales (CE) syncs with D365FO for invoicing and fulfilment.

  • Product Sync
    Products created in FO are synced to CE so sales reps can quote and sell accurately.

  • Vendor Management
    Vendors created in CE (via Power Apps) get synced to FO for procurement processes.

  • Use case: Sync customers, orders, vendors, etc., with Power Apps or D365 CE.

  • Setup: Prebuilt mappings and extensible framework.

✅ Great for connected apps, low-code solutions, and seamless FO + CE experiences.

๐Ÿ”Ÿ Consuming External Web Services (from X++)

D365 FO can consume external API's directly via X++.

๐Ÿ” Overview

D365FO supports integration with external systems via HTTP-based web services (REST/SOAP). As a technical consultant, you often need to call third-party APIs for real-time data exchange like:

  • Fetching exchange rates

  • Sending invoice data to an external system

  • Validating GST/TIN

  • Sending SMS or email notifications

This article explains how to consume external REST/SOAP web services from X++ using System.Net.HttpWebRequest, System.Net.HttpClient, or a custom .NET class wrapper in D365FO.

๐Ÿ” Security Considerations

  • D365FO runs in sandboxed environments, so HTTP calls are allowed only from batch or async operations.

  • Use Azure Key Vault to store API keys or secrets securely.

  • Use Sys.Net.HttpClient only in trusted and controlled scenarios.

  • Avoid direct synchronous API calls in forms or synchronous processes.

๐Ÿ› ️ Common Use Cases

Use Case        API Type    Call Type
Get weather data        REST    GET
Validate GSTIN/PAN        REST    POST
Send SMS via Twilio        REST    POST
Fetch stock prices        REST    GET
Submit Invoice to Tax Portal        SOAP    POST
๐Ÿšง Best Practices
  • Use Batch Jobs or SysOperation Framework for calling external APIs.

  • Log responses for traceability in a custom log table.

  • Implement retry logic for transient failures.

  • Use Sys.Net.HttpClientFactory if you're managing many connections.

๐Ÿ“ Summary

FeatureREST (HttpClient)    SOAP (Service Ref)    .NET DLL
Ease of Use    Easy    ⚠️ Moderate    Flexible
Real-time    Yes    Yes    Yes
Reuse Logic    ⚠️ Low    ⚠️ Medium    High
OAuth/JWT Support    Yes (custom headers)    Manual    Excellent
  • Class used: System.Net.HttpClient, CLRObject, etc.

  • Use case: Call a shipping API to get tracking info, or sync the external catalogue.

✅ Enables integration with external REST/SOAP services from within D365 FO.

Final Thoughts

D365 FO offers integration options for every need — real-time APIs, bulk syncs, event-driven messaging, and analytics.