Posts

Showing posts from August, 2025

JSON-Based HTTP POST Request from X++ to Retrieve an Access Token

In today's connected systems, integrations between Dynamics AX and external APIs are essential. One common scenario is retrieving an access token from a remote API for authentication. In this post, I'll show you how to make a POST request with JSON from X++ and handle the response. We'll walk through a complete example where we send credentials to an API and parse the response to retrieve an access token. Prerequisites To follow along, you should have: Basic familiarity with X++ Access to System.Net and System.IO namespaces via CLR Interop A configured HRMParameters table to store credentials X++ code: System.Net.HttpWebRequest                 request; System.Net.HttpWebResponse              response; System.IO.StreamWriter                       streamWriter; System.IO.StreamReader              ...

Sending Form Data from form in D365FO Using a Button Click

In this blog post, I’ll walk you through how to implement a button click handler in Dynamics 365 Finance and Operations (D365FO) to send data to an external API.   Requirement I had a requirement where I needed to send the selected worker's data to an external API when a button is clicked on the HcmWorkerV2 form. To achieve this, I used a form control event handler that is triggered when the custom button is clicked. Implementation Here’s the X++ code that handles the button click: [FormControlEventHandler(formControlStr(HcmWorkerV2, SendApiData), FormControlEventType::Clicked)] public static void SendApiData_OnClicked(FormControl sender, FormControlEventArgs e) {     FormCommandButtonControl callerButton = sender as FormCommandButtonControl;     FormRun form = callerButton.formRun();     // Get the form datasource and current worker record     FormDataSource hcmWorker_ds = form.dataSource(formDataSourceStr(HcmWorkerV2, HcmWorker)) as...

Passing Multiple Selected Records from a Form to an SSRS Report in D365FO

Recently, I had a requirement in Dynamics 365 Finance & Operations (D365FO) to pass multiple selected records from a form to an SSRS report. To achieve this, I used the MultiSelectionHelper class, which allows you to retrieve all selected records from a form's grid.   Step-by-Step Implementation To implement this functionality, I created: A contract class to hold the list of selected RecId s. A controller class to fetch the selected records using MultiSelectionHelper. A data provider (DP) class to process and insert the selected records into a temporary table for the report. Contract Class The contract class contains a list of RecId s: List recid; [     DataMemberAttribute('recId'),     SysOperationHelpTextAttribute(literalStr("Rec Id")),     SysOperationLabelAttribute(literalStr("Rec Id")),     SysOperationDisplayOrderAttribute('0'),     AifCollectionType('return', Types::Int64) ] public List parmRecId(List _re...

How to Show or Hide a Tablix Row in SSRS Report in D365FO

Image
Recently, I had a requirement in Dynamics 365 Finance & Operations (D365FO) where I needed to conditionally show or hide a specific row inside a tablix in an SSRS report. In this blog, I’ll explain how I achieve this by using a value , and use it to control row visibility inside a tablix. Scenario Let’s say your tablix contains multiple rows: | Employee | Department | Salary | Extra Info Row (Bonus, Notes, etc.) | You want to show/hide the "Extra Info" row based on a value selected by the user. Step-by-Step Implementation      Design your tablix with multiple rows. For example: Row 1: Employee Info Row 2: Salary Details Row 3: Extra Info (this is the row we’ll hide/show)      Set Visibility for the Specific Row Click on the row handle (left side grey bar) for the row you want to show/hide. Right-click → Row Visibility… Choose: "Show or hide based on an expression"                ...

Retrieving Worker Personal & HR Details in D365FO Using X++

  Introduction In HR and payroll modules of Dynamics 365 Finance & Operations, it’s common to retrieve detailed employee information — from personal details like marital status and gender , to financial dimensions and reporting structure . In this post, I’ll share how I query D365FO tables to get: Personal details (marital status, gender, birth date, etc.) Age calculation CNIC details Financial dimensions (Department, Business Unit) Reporting hierarchy (Who the worker reports to) Getting Personal Details of a Worker Fetch details like marital status, gender, birth date, number of dependents, and ethnic origin. select hcmPersonDetails     where hcmPersonDetails.Person == hcmWorker.Person     join dirPartyTable         where dirPartyTable.RecId == hcmPersonDetails.Person     join hcmPersonPrivateDetails         where hcmPersonPrivateDetails.Person == dirPartyTable.RecId     join hcm...

Calling an External API from D365FO Using X++ to Retrieve a Token

In many Dynamics 365 Finance & Operations (D365FO) integrations, we need to authenticate with an external system before making API calls. The authentication is usually done by sending credentials (such as email, password, and API token) to the endpoint, which returns a JWT (JSON Web Token) or similar authentication token. In this post, I’ll share how I implemented an X++ method that: Sends login details to an external API in JSON format. Reads the API response. Deserializes the JSON into a usable object. Includes error handling for robust integration. Requirement Connect to an external REST API, send authentication details stored in the HRMParameters table, and retrieve an authentication token for use in subsequent API calls. Approach Use CLR Interop to call .NET classes from X++. Build a JSON request body using strFmt . Send the request via System.Net.HttpWebRequest . Read the API’s JSON response. Deserialize it into a custom ResponseTokenData clas...

Restricting Date Selection in Dynamics 365 FO using X++

Scenario Recently, I had a requirement in Dynamics 365 Finance & Operations to restrict the user from entering a transaction date that: Is greater than the current date (future date restriction). Is earlier than 2 days before the current date (past date restriction). In short: Allowed date range = From 2 days ago to today . Any date outside this range should trigger an error message and reset to today’s date. Solution Approach For this requirement, I used the addDays method in X++. The  addDays method allows us to easily calculate a date by adding or subtracting days from a given date. Syntax: addDays(_t, _value) _t : A utcDateTime value representing the starting date and time. _value : Number of days to add (positive) or subtract (negative). Example: DateTimeUtil::addDays(DateTimeUtil::utcNow(), -2); This returns the date & time 2 days before the current date. Implementation in Form Data Field Event We can handle the validation when the Tr...