web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Query Service , How to return labels for enum fields

(0) ShareShare
ReportReport
Posted on by 690

Hi all,

I am retrieving data using Query Service using QueryMetadata on a table in AX. I use paging because I have lot of data. In the table I have 3 fields that are Base Enum type.

When I get the result dataset and the data table containg the data I only get numbers in the Enum fields of the table (It is returning me Enum value) and not the label. At client when I get this data it does not really make much sense.

I know that I can get the Enum metadata from Metadata Service and then somehow convert these values (I get in query service) to labels. But this I guess would be a row wise operation which I want to avoid because I guess that would be heavy.

Is there any way that I get the labels directly as a result from QueryService.ExecuteQuery(...) method ?

- Girija

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Getting metadata isn't a row-wise operation. You need to get metadata for your enum only once - the enum definition is the same for all rows.

    Using the metadata service is it the right way for getting enum metadata.

  • Girija Shankar Beuria Profile Picture
    690 on at

    Hi Martin,

    Thanks for looking at my question. I know that I will have to get the metadata only once, but my issue comes when I have to combine the data I get in query service (in that case the field gets me only enum value). In that case I will have to lookup to the result which I get through Metadata service using the field value.

    Since I have many rows the look up operation will be heavy and I wanted to avoid that. I was looking if there is any operation that gets me the enum label directly when I use the query service so I do not have to lookup values to get the label.

    - Girija

  • Suggested answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    You either don't understand what I'm saying or you think that reading a value from variable in memory is "heavy".

    Let me write the solution as pseudo-code; it could make it clearer for you.

    // The single call to metadata service to get metadata
    // for one or more enums
    EnumMetadata[] metadata = metadataSvc.GetEnumMetadataByID(...);
    
    // Here you can transform EnumMetadata to something easier
    // to process, such as a Dictionary mapping enum values to labels
    
    foreach (var row in rows)
    {
        // Get the label for the enum value of the row. No service call needed
        // because you already have everything in the variable called metadata.
    }
    
  • Girija Shankar Beuria Profile Picture
    690 on at

    Martin,

    I understand what you are saying and I am aware of this approach/code already. Please look at my initial post which says :

    "I know that I can get the Enum metadata from Metadata Service and then somehow convert these values (I get in query service) to labels. But this I guess would be a row wise operation which I want to avoid because I guess that would be heavy."

    All I was looking is if there is a better simpler way (some setting for Query service which will return me the Enum label in the datset rather than the value).

    Here is how I see it if I take the Metadata Service approach (Which I know and you also suggested).Let me know if I disagree ?

    1. Get the enums metadata by GetEnumMetadataByName - FIRST SERVICE CALL TO AX

    2. From the above get all the Labels (This will give me a list of ID (e.g. : @SYS....)

    3. The Get the labels by GetLabelMetadataById -  SECOND SERVICE CALL TO AX

    4. Now Merge the data in Step 1 and Step 3 to create a datatable for enum (EnumValue, EnumName, EnumLabel)

    5. Now get the data from AX using Query Service - THIRD CALL TO AX

    6. Now use LINQ or something else and iterate over all rows in datatable in STEP 5  and in each row use the enum value and lookup label in datatable created in 4

    There were two concerns I had:

    1. I am essentially making 3 calls to AX for retrieving the data I want

    2. Imagine my data (in Step 5) has max rows as per query service limit (25K). In that case I thought Step 6 would be an expensive operation.

    I was looking at if there is any setting that we can do in Query Service so that the Enum Labels are returned as part of the dataset rather than the values which it is currently doing. Because I could not find much on the web regarding this I thought that this would be the best place to ask.

    Hope this is clear.

    - Girija

  • Verified answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Yes, you're doing only three calls to get everything you need. I don't see any problem at all. Step 6 isn't more expensive just because you read some value from a variable. A lookup to hash table in memory (or something) is definitely not an expensive operation. Fetching labels in AX and transfer them over network would like be more expensive.

    To summarize it: you won't get labels from the query service service, because it's not what it does. And there is also no real performance problem in making a few calls to to the metadata service nor reading labels from memory.

  • Girija Shankar Beuria Profile Picture
    690 on at

    Ok. That is what I wanted to know. It is not possible directly.

  • Community Member Profile Picture
    on at

    Hi Girja,

    I am trying to do something similar to you. I am using the ExecuteQuery method to pull some data and some of the fields are of Base Enum type.

    Using the MetadataService I can get the table meta data I am querying on and then for each field using the DataFieldMetadata class I am able to use the BaseType method to check whether the field is Enum or not but I don't know how to retrieve the Enum Type ID or name for a particular field so that I can then use the GetEnumMetadataById or GetEnumMetadataByName methods to retrieve the values?

    Do you have some suggestions that might help me?

    Thanks,

    Ramesh

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans