Alex Meyer
  • About Me
  • Professional Skill Set
  • Resources
    • D365FO Admin Toolkit
    • D365FO Version Metadata
    • D365FO Security Course
    • Books
    • YouTube Videos
    • Podcasts
    • Social Media
    • Downloads
    • No Null Points Blog
    • AX 2012 Erd
  • Microsoft Cloud Blogs
    • Dynamics 365 for Finance & Operations Blog
    • D365FO Security Topics
    • Dynamics 365 and Power Platform Blog
    • Microsoft Azure Platform Blog
  • Terms of Use
Select Page

Getting D365FO Object Labels in .NET

by Alex | Mar 20, 2018 | Dynamics 365 for Finance and Operations | 14 comments

With the redesign of the X++ compiler (that I go over in depth inĀ this post) to allow for interfacing with C#/.NET in D365FO I’ve tried every chance I get to code my complex business logic in .NET instead of X++. Mostly because, as a .NET developer by trade, I feel more comfortable in that language but also because I think personally that .NET gives you more flexibility than X++ does. But with this decision comes a number of challenges, first and foremost there are some processes that become very difficult without some standard X++ classes and methods.

One of those tasks is trying to get labels for different objects from within a C#/.NET project. Here are the steps I had to take to be able to accomplish this:

First I had to reference the necessary X++ libraries to be able to actually get to the classes/methods necessary, here are the libraries you will need to reference.

  • Microsoft.Dynamics.AX.Metadata
  • Microsoft.Dynamics.AX.Metadata.Core
  • Microsoft.Dynamics.AX.Server.Core
  • Microsoft.Dynamics.AX.Xpp.AxShared
  • Microsoft.Dynamics.AX.Xpp.Support

Now we can start looking at how to get labels for different object types.

In the first example below we are looking specifically at tables, you can see we now have access to the X++ Dictionary which is a very useful object especially if you want to query objects in the system. In this case we use this Dictionary object to get an AxTable object and that allows us to get the label tied to that object.

In the second example, we are looking at menu items. In this case we are specifically looking at menu item displays but all menu item types act in a very similar way. We are able to get back a menu item object using the MetadataSupport class which is an important class when dealing with objects and their metadata. From there we are able to get the label for this, but as anyone who deals with AX/D365 knows this label is actually the label Id and is associated to the actual label. To get the actual label we now need to use another critical library the LabelHelp class, using this we are able to convert this label Id to the actual label itself.

In the final example, we are looking at data entities which are fairly similar to the menu items process we used in the previous example. We are again able to use the MetadataSupport class to get back a data entity object and then use the LabelHelper class to get the label of the object.

I have also provided a text copy of the code above.

public static void GetMetadataLabels()
 {
 Microsoft.Dynamics.Ax.Xpp.Dictionary dict = new Microsoft.Dynamics.Ax.Xpp.Dictionary();
 string tableAOTName = "VendTable";
 string tableLabel = dict.Tableobject(dict.Tablename2id(tableAOTName)).Label();
 //tableLabel = Vendors

string menuItemAOTName = "VendTableListPage";
 string menuItemLabel = Microsoft.Dynamics.Ax.Xpp.LabelHelper.GetLabel(
 Microsoft.Dynamics.Ax.Xpp.MetadataSupport.GetMenuItemDisplay(menuItemAOTName).Label);
 //menuItemLabel = All vendors

string dataEntityAOTName = "VendVendorEntity";
 string dataEntityLabel = Microsoft.Dynamics.Ax.Xpp.LabelHelper.GetLabel(
 Microsoft.Dynamics.Ax.Xpp.MetadataSupport.GetDataEntityView(dataEntityAOTName).Label);
 //dataEntityLabel = Vendors
 }

While there are certain things that still have to be done in X++, I hope this shows that you can do business logic within C#/.NET for D365FO.

14 Comments

  1. Artem T
    Artem T on November 5, 2018 at 8:18 am

    Hi Alex, tried to use your code on D365FO version 8.1 Update 20, could not make it to work. I’ve added all references from your screenshot, still it could not find LabelHelper class at Microsoft.Dynamics.Ax.Xpp namespace.

    Any ideas why?

    Reply
    • Alex
      Alex on November 6, 2018 at 8:36 am

      Artem,

      I just tested this on an 8.0 and 8.1 PU20 box and was able to successfully build using the same code/DLLs in both. Intellisense was still showing the LabelHelper namespace as well.

      LabelHelper

      If you provide what errors you are getting, might be able to help diagnose/troubleshoot the issue.

      Reply
  2. Artem T
    Artem T on November 13, 2018 at 4:16 am

    Thank you for the reply, you could see my error here:
    https://preview.ibb.co/fsLK0A/Screenshot-13-Nov-2018-11-09-41.jpg

    Reply
  3. Artem T
    Artem T on November 13, 2018 at 4:33 am

    I found what was the issue. I was missing one of the references: Microsoft.Dynamics.AX.Xpp.AxShared

    Reply
  4. Vladimir
    Vladimir on August 8, 2020 at 9:59 am

    Hi Alex, how can I get a list of all label files for all languages?

    Reply
    • Alex
      Alex on August 9, 2020 at 7:51 am

      Vladimir,

      You can use labelId2String method which takes in a language parameter, here’s an example: https://community.dynamics.com/ax/b/axdaily/posts/getting-label-text-in-different-languages

      Reply
  5. vidhya
    vidhya on March 4, 2022 at 5:34 am

    can you help me to get list of objects against label id in X++ (similar to AOT find reference)

    Reply
    • Alex
      Alex on March 4, 2022 at 2:31 pm

      You can use the same MetadataSupport library in X++ like you can in C#, here is an example: http://dev.goshoom.net/2016/11/new-metadata-api/

      Reply
  6. Eiso
    Eiso on April 24, 2023 at 7:58 am

    Hello,
    How can I get all label id for all layers from label text?

    Reply
    • Alex
      Alex on April 24, 2023 at 9:21 am

      Eiso,

      You should be able to use the ‘GetAllLabels’ method for this:

      Reply
  7. Ashish
    Ashish on October 31, 2023 at 9:21 pm

    Hi Alex

    I was trying to connect to azure storage using x++.

    So the c# code I have written to upload the files to azure blob storage is working fine as standalone c# project

    Now I wanted to use the same c# project or more importantly the same logic in x++ but not sure how to design that or start

    In a way

    Step 1 create a x++ vs solution Azureblobstorage solution

    Step 2 Add x++ project Azureoperation

    Step 3 create a c# class library with the same solution

    Step 4 Make a reference of c# library in our x++ project

    Reply
    • Alex
      Alex on October 31, 2023 at 9:38 pm

      Ashish,

      Is there a reason you want to do this logic in X++ logic? I think it may be better to reuse your work you have already done and create a .NET project that your X++ project can call.
      Step 1: Create X++ project
      Step 2: Create .NET project with the Azure blob logic
      Step 3: Add .NET reference to X++ project
      Step 4: Call the .NET project from X++

      Reply
  8. Ashish
    Ashish on November 9, 2023 at 1:38 am

    Hi Alex

    No I am not sure if we can use all methods of the c# by referencing in x++ or there will be some limitations

    Reply
    • Alex
      Alex on November 9, 2023 at 9:30 am

      Ashish,

      Technically there is nothing stopping you from calling any C# method from X++ but I would recommend using each language when appropriate (use X++ when it is a better fit for what you are wanting to do and use C# when it is a better fit).

      Reply

Submit a Comment Cancel reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Search

Recent Posts

  • ISM Telemetry for Finance and Operations Overview May 6, 2025
  • Dynamics 365 Finance & Supply Chain License Enforcement Overview April 29, 2025
  • Microsoft MVP Summit 2025 Overview March 27, 2025
  • D365FO Telemetry Data FAQs March 19, 2025
  • D365FO Security Myth: Segregation of Duties Can Be Done at the Duty Level February 18, 2025
  • X
  • RSS

Designed by Elegant Themes | Powered by WordPress