Alex Meyer
  • About Me
  • Professional Skill Set
  • Resources
    • D365FO Security Course
    • Books
    • YouTube Videos
    • 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
Select Page

Getting D365FO Object Labels in .NET

by Alex | Mar 20, 2018 | Dynamics 365 for Finance and Operations | 8 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.

8 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

Submit a Comment Cancel reply

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

Search

Recent Posts

  • Spring 2023 – Presenting at Upcoming User Group Conferences March 30, 2023
  • Utilizing Telemetry Data Within D365FO March 28, 2023
  • Potential Upcoming Licensing Changes in D365FO? February 21, 2023
  • Netmodule File Missing Error in 10.0.31 February 17, 2023
  • Security & Audit Features Added in 10.0.31 February 8, 2023
  • Twitter
  • RSS

Designed by Elegant Themes | Powered by WordPress