AX / D365FO – How to get environment url using X++

Create a runnable class and add the below code. On executing the class, code will display the current Environment URL

  public static void main(Args _args)
    {
        // Environment URL
       System.Uri currentHost = new System.Uri(UrlUtility::getUrl());
        str url = currentHost.GetLeftPart(System.UriPartial::Authority);
        info(strFmt("Environment URL: %1", url));
    }

Leave a comment