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 :
Microsoft Dynamics AX (Archived)

How to set label of a Base Enum dynamically from axapta

(0) ShareShare
ReportReport
Posted on by 792

Hi all,

I have a base enum TennisPlayer with two values say Player1 (label: Federar) and Player2 (label: Nadal). This enum is used as the data source of a combobox item in one of my forms.

Now from one of my classes I want to programmatically set the label of the Item2 of my enum to say Murrey (if a particular condition is satisfied). How to set the label of the enum? I cant find solution anywhere.

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    235,914 Most Valuable Professional on at
    RE: How to set label of a Base Enum dynamically from axapta

    Sagnik, dialog is a class modifying a form at runtime, You obviously can modify forms at runtime even if you don't do it through the one specific class.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: How to set label of a Base Enum dynamically from axapta

    I believe brother instead of setting label values in Enum object. You should consider creating separate labels and you can change the labels text values programmatically.

    Check the following blog post for how to change labels value using X++

    thinkinginax.blogspot.com/.../changing-labels-values-using-x.html

    Hope this helps you.

  • Mohammad Raziq Ali Profile Picture
    2,476 on at
    RE: How to set label of a Base Enum dynamically from axapta

    Hi sagnik,

    your requirement is Generating runtime Enum value but you said enum has already datasource attached with it which is static.

    my suggestion to you is,

    1. You dont use static enum as datasource at first , then

    2. Generate Runtime Enum using Code, 

    please let us know.

    Please verify the answer if it helps you.

  • Sagnik Majumder Profile Picture
    792 on at
    RE: How to set label of a Base Enum dynamically from axapta

    Hi Palle, thanks for the reply. But I have already seen this post. But I donot have a dialog, nor a dialogfield. I already have a form where an enum is set statically as the data source. Hence we don't have a FormBuildComboBoxControl object anywhere. In run time I want to modify the label of one of that enum's values.

  • Suggested answer
    PA-22040759-0 Profile Picture
    6,194 on at
    RE: How to set label of a Base Enum dynamically from axapta

    The dialog is a form, I don't if you are aware of that.

    I have tried a few things, and no matter what I try I can't change the comboBox's first item, the one with the value of 0, when it has been built.

    A better approach than using a combobox based on an enum, just to change the different text selections, would be to build the combox control yourself from scratch. That is adding elements yourself in the first place, rather than changing element.

    Have a look at the \Classes\SysFormEnumComboBox class for inspiration.

  • Ali Zaidi Profile Picture
    4,655 on at
    RE: How to set label of a Base Enum dynamically from axapta

    Very strange scenario, why you want to change the label at runtime, instead you can update the enum label in data repository and used that.

    By the way one way to add enum value at run time as follow it is not exact answer but possible some modification helps

    static void addEnumvalue(Args _args)

    {

       #AOT

       TreeNode        treeNodeEnum;

       ;

       treeNodeEnum    = TreeNode::findNode(#BaseEnumsPath);

       treeNodeEnum    = treeNodeEnum.AOTfindChild('ABCModel');

       treeNodeEnum.AOTadd('Test');

       treeNodeEnum.AOTsave();

    }

  • Sagnik Majumder Profile Picture
    792 on at
    RE: How to set label of a Base Enum dynamically from axapta

    Thanks Jo for the reply. I have already seen this example, but I fear, this is not what I wanted. I don't use a dialog and neither a dialogfield. I already have a form where an enum is set statically as the data source. Hence we don't have a FormBuildComboBoxControl object anywhere. In run time I want to modify the label of one of that enum's values.

  • Suggested answer
    PA-22040759-0 Profile Picture
    6,194 on at
    RE: How to set label of a Base Enum dynamically from axapta

    The label of the enum is given, well from the enum.

    Maybe you can get some inspiration from this article: blogs.msdn.com/.../434146.aspx

    But I think maybe you are going down a wrong path. The idea with an enum is that the outcomes are fixed.

  • Suggested answer
    Jo Neetesonne Profile Picture
    175 on at
    RE: How to set label of a Base Enum dynamically from axapta

    Hey

    You should be able doing so by using some parts of the code below.

    static void comboBoxHiJacker(Args _args)

    {

       Dialog                      dialog = new Dialog();

       DialogField                 dialogField;

       FormBuildComboBoxControl    formComboBoxControl;

       ;

       // Any enum, except NoYes, will do.

       dialogField = dialog.addField(typeId(ABC));

       formComboBoxControl = dialogField.control();

       formComboBoxControl.enumType(0);

       formComboBoxControl.label("My combo box");

       formComboBoxControl.items(3);

       formComboBoxControl.item(1);

       formComboBoxControl.text("Item 1");

       formComboBoxControl.item(2);

       formComboBoxControl.text("Item 2");

       formComboBoxControl.item(3);

       formComboBoxControl.text("Item 3");

       dialog.run();

       info(dialogField.value());

    }

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans