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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to get labelID for all layers from label text though code?

(0) ShareShare
ReportReport
Posted on by 150

Hello,

I would like to get the Label ID from all Layers that contain text entered from form controls.

community.dynamics.com/.../1296437

I am implementing it with reference to the above link,
A compilation error has occurred as follow.

compileerror.jpg
Also, the sample code in this link only allows you to get the LabelID for the specified Layer.


Any sample code or any advice would be greatly appreciated.

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    300,195 Super User 2025 Season 2 on at
    RE: How to get labelID for all layers from label text though code?

    Hi Akshi,

    You might have forgotten a reference, like suggested by the error. Instead asking coding, maybe it would be better if you share the class you created. You can use the rich formatting and then Insert  > Code to paste the code and share what you have done so far.

  • akshi Profile Picture
    150 on at
    RE: How to get labelID for all layers from label text though code?

    Hi

    I created it with reference to the above link to get the label file. As a result, the above error occurs.

    using Microsoft.Dynamics.AX.Metadata.Kernel;
    using Microsoft.Dynamics.AX.Metadata.Service;
    Public static class TestGetLabelIdClass
    {
        public static TestLabelIdTmpTable getLabelIdInfo(Str4095 _labelTxt)
        {
            TestLabelIdTmpTable testLabelIdTmpTable;
         
            IMetaModelService service = new MetaModelServiceFactory().Create(Accessor::MetadataProvider);
            var labelFiles = service.GetLabelFileNames();
    
            Set prefixes = new Set(Types::String);
            var enumerator = labelFiles.GetEnumerator();
            while (enumerator.MoveNext())
            {
                int positionOf_ = strFind(enumerator.Current, '_', 1, strLen(enumerator.Current));
                str prefix = subStr(enumerator.Current, 1, positionOf_ - 1);
                prefixes.add(prefix);
            }
    
            return testLabelIdTmpTable;
        }
    
    }

    First, I am trying to get all label file list.

  • Martin Dráb Profile Picture
    236,974 Most Valuable Professional on at
    RE: How to get labelID for all layers from label text though code?

    The first error says that you're referring to Microsoft.Dynamics.AX.Metadata.Kernel for some reason, but you haven't added a reference to an assembly containing this namespace.

    Regarding Accessor, maybe you can get rid of it completely. I don't know why you're using your current approach, but what about switching to new MetadataProviderFactory().CreateRuntimeProviderWithExtensions()?

  • akshi Profile Picture
    150 on at
    RE: How to get labelID for all layers from label text though code?

    Hello Martin,

    Thanks for your info.

    I fixed it as below, but the reference error still occurs.

    Can you share how to add reference?

    using Microsoft.Dynamics.AX.Metadata.MetaModel;
    using Microsoft.Dynamics.AX.Metadata.Storage;
    using Microsoft.Dynamics.AX.Metadata.Storage.Runtime;
    using Microsoft.Dynamics.AX.Metadata.Core.MetaModel;
    
    var environment = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory.GetApplicationEnvironment();
            var runtimeConfiguration = new RuntimeProviderConfiguration(environment.Aos.PackageDirectory);
            var metadataProvider = new MetadataProviderFactory().CreateRuntimeProviderWithExtensions(runtimeConfiguration);
    
            //IMetaModelService service = new MetaModelServiceFactory().Create(Accessor::MetadataProvider);
            var labelFiles = metadataProvider.GetLabelFileNames();
    
            Set prefixes = new Set(Types::String);
            var enumerator = labelFiles.GetEnumerator();
            while (enumerator.MoveNext())
            {
                int positionOf_ = strFind(enumerator.Current, '_', 1, strLen(enumerator.Current));
                str prefix = subStr(enumerator.Current, 1, positionOf_ - 1);
                prefixes.add(prefix);
            }

    Referror.jpg

    Do it make a project with .Net and refer to it from the X project?

  • akshi Profile Picture
    150 on at
    RE: How to get labelID for all layers from label text though code?

    If you have any helpful blogs or information about how to get the AOT label file list, please share it.

  • Martin Dráb Profile Picture
    236,974 Most Valuable Professional on at
    RE: How to get labelID for all layers from label text though code?

    I see several bugs:

    1. 'using' statements needs to be defined in the class, not inside a method together with your code.
    2. You're calling GetApplicationEnvironment() as if it was an instance method, not a static one.
    3. There it seems to be no GetLabelFileNames() method.

    I think you gave us wrong information about which thread you tried to follow. I believe you meant   .  Didn't you forget to add a reference to AOSKernel.dll?

  • akshi Profile Picture
    150 on at
    RE: How to get labelID for all layers from label text though code?

    The using statement is declared as follows. Declaring a Kernel gives an error again.

    using Microsoft.Dynamics.AX.Metadata.Kernel;
    using Microsoft.Dynamics.AX.Metadata.MetaModel;
    using Microsoft.Dynamics.AX.Metadata.Storage;
    using Microsoft.Dynamics.AX.Metadata.Storage.Runtime;
    using Microsoft.Dynamics.AX.Metadata.Core.MetaModel;
    using Microsoft.Dynamics.Ax.Xpp.MetadataSupport;
    using Microsoft.Dynamics.ApplicationPlatform.Environment;
    public static class TestGetLabelIdClass
    {
        /// 
        /// Class entry point. The system will call this method when a designated menu 
        /// is selected or when execution starts and this class is set as the startup class.
        /// 
        /// The specified arguments.
        public static void main(Args _args)
        {
            var environment = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory.GetApplicationEnvironment();
            var runtimeConfiguration = new RuntimeProviderConfiguration(environment.Aos.PackageDirectory);
            var metadataProvider = new MetadataProviderFactory().CreateRuntimeProviderWithExtensions(runtimeConfiguration);
    
            //IMetaModelService service = new MetaModelServiceFactory().Create(Accessor::MetadataProvider);
            var labelFiles = metadataProvider.GetLabelFileNames();
    
            Set prefixes = new Set(Types::String);
            var enumerator = labelFiles.GetEnumerator();
            while (enumerator.MoveNext())
            {
                int positionOf_ = strFind(enumerator.Current, '_', 1, strLen(enumerator.Current));
                str prefix = subStr(enumerator.Current, 1, positionOf_ - 1);
                prefixes.add(prefix);
            }
        }
    
    }

    Could you tell me how to add a reference?

    Thanks.

  • Martin Dráb Profile Picture
    236,974 Most Valuable Professional on at
    RE: How to get labelID for all layers from label text though code?

    Your question suggests that you didn't add the reference, which explains why your code can't compile. The compiler can't load the assembly containing objects that you're using in your code.

    Open you project, right-click References node, choose Add Reference... and add AOSKernel.dll from the bin folder of your modelstore (e.g. k:\AosService\PackagesLocalDirectory\bin\).

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 701 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 588 Most Valuable Professional

#3
Sumit Singh Profile Picture

Sumit Singh 544

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans