Pass and Retrieve Parameters from a URL in Dynamics 365 Finance and Operations - Microsoft Dynamics 365 Vietnam

Microsoft Dynamics 365 Vietnam

Song Nghia - Microsoft Dynamics 365 Vietnam

Breaking

Sunday, May 4, 2025

Pass and Retrieve Parameters from a URL in Dynamics 365 Finance and Operations

How to Pass and Retrieve Parameters from a URL in Dynamics 365 Finance and Operations

In some cases, you may want to pass data—like a PO number or journal ID—through the URL parameters when navigating in Dynamics 365 Finance and Operations (D365 F&O). A typical scenario is when a user clicks a menu item, and you want to process some values passed via the URL.

In this blog post, I’ll show you how to read parameters from the URL using X++, with a simple code example.

Use Case

Assume you have a class called ARCCancelPOsByEmail, which is linked to an Action menu item. You want the system to retrieve values like ponumber and journalId directly from the URL, like this:

https://yourD365url/?mi=YourMenuItemName&ponumber=PO123456&journalId=GEN0001

How to Read Parameters from the URL

Here's the sample code in your class's main() method:

internal final class ARCCancelPOsByEmail
{
    public static void main(Args _args)
    {
        str ponumber = System.Web.HttpUtility::ParseQueryString(URLUtility::getUrl()).Get('ponumber');
        str journalId = System.Web.HttpUtility::ParseQueryString(URLUtility::getUrl()).Get('journalId');
        info(strFmt("PO Number: %1 - Journal ID: %2", ponumber, journalId));
    }
}

Explanation

  • URLUtility::getUrl() retrieves the current URL from the browser.
  • System.Web.HttpUtility::ParseQueryString(...) parses the query string.
  • .Get('ponumber') fetches the value of the parameter ponumber.
  • You can fetch other parameters the same way.

How to Use

  1. Create an Action menu item that points to the class ARCCancelPOsByEmail.
  2. Add the menu item to a menu, or navigate to it by modifying the URL directly.
  3. Pass the values you need through the URL, for example:
    https://yourD365url/?mi=ARCCancelPOsByEmail&ponumber=PO9876&journalId=JRN2025
  4. When executed, the system will display a message like:
    PO Number: PO9876 - Journal ID: JRN2025

Notes

  • This method only works when accessing the class via a menu item in the browser. It won’t work when running the class as a batch or from code.
  • If your values include special characters, make sure the URL is properly encoded.

I hope this post helps you implement URL-based parameter handling in D365 F&O more easily. If you found this useful, feel free to share it with others!

No comments:

Post a Comment