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 change the value of the Enum-Combo Box in Ax 2012?

(0) ShareShare
ReportReport
Posted on by

Hello I have created a new Enum in Ax 2012 with name Certificates and 4 elements in it as Bank,Insurance,Leave and salary.

I have added this Enum in form inside a group.

Now when ever I select as value, as per that value the form must change. only first if block(in the below code) is working after that it is not working even if I change the value in the combobox.

For this I had written the below code by overriding selectionChange of combobox :

public int selectionChange()  //
{
int ret;
CXT_MDrop CXT_MDrop1;

ret = super();


if(CXT_MDrop1.Certificates == Certificates::Bank)
{
gg1.visible(true); //Group1
gg2.visible(false);//Similarly group2 and so on..
gg3.visible(false);
gg4.visible(false);
}
else if(CXT_MDrop1.Certificates == Certificates::Insurance)
{
gg1.visible(false);
gg2.visible(true);
gg3.visible(false);
gg4.visible(false);
}
else if(CXT_MDrop1.Certificates == Certificates::Leave)
{
gg1.visible(false);
gg2.visible(false);
gg3.visible(true);
gg4.visible(false);
}
else if(CXT_MDrop1.Certificates == Certificates::Salary)
{
gg1.visible(false);
gg2.visible(false);
gg3.visible(false);
gg4.visible(true);
}

//switch(CXT_MDrop1.Certificates)
//{
//case Certificates::Bank:
//{
//gg1.visible(true);
//gg2.visible(true);
//gg3.visible(false);
//gg4.visible(false);
//break;
//}
//case Certificates::Bank:
//{
//gg1.visible(true);
//gg2.visible(false);
//gg3.visible(false);
//gg4.visible(false);
//break;
//}
//case Certificates::Bank:
//{
//gg1.visible(true);
//gg2.visible(false);
//gg3.visible(false);
//gg4.visible(false);
//break;
//}
//case Certificates::Bank:
//{
//gg1.visible(true);
//gg2.visible(false);
//gg3.visible(false);
//gg4.visible(false);
//break;
//}
//}


delete_from CXT_MDrop1;

return ret;
}

Similar code I tried to write in Active() of Form Data Source. But it is not working.

Need help. Thanks in Advance

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: How to change the value of the Enum-Combo Box in Ax 2012?

    Okay Krishna I will check your solution later. Thanks for both of you.

  • Suggested answer
    Martin Dráb Profile Picture
    235,968 Most Valuable Professional on at
    RE: How to change the value of the Enum-Combo Box in Ax 2012?

    What she used is the datasource buffer I meant. It's an automatically created variable with the same name as the datasource.

    Please read Using Variables with Forms [AX 2012]. You really should get used to reading the documentation; it's been created exactly for answering your questions.

  • krishna.rao@dax Profile Picture
    3,002 on at
    RE: How to change the value of the Enum-Combo Box in Ax 2012?

    I think in active method of datasouce also need to call the piece of code..

    or else will face issue while moving from one record to another..

  • Community Member Profile Picture
    on at
    RE: How to change the value of the Enum-Combo Box in Ax 2012?

    Hi Krishna and Martin now I am getting desired output but not creating any buffer variable of table or form data source but what my senior actually did in modified method of the form data source  is that she directly used tablename.certificates without creating any table or data source variable and it is working fine.

    May be somewhere else I would have done something wrong?

  • Martin Dráb Profile Picture
    235,968 Most Valuable Professional on at
    RE: How to change the value of the Enum-Combo Box in Ax 2012?

    I wouldn't recommend calling refresh() and active() from modified(), because it would have impact to unsaved values. A better approach is using a separate method (e.g. updateDesign()) called from both active() and modified().

    I thought we would fix the code first and then look at other requirements (such as calling in from activation in addition to selection change) later and only if needed.

  • krishna.rao@dax Profile Picture
    3,002 on at
    RE: How to change the value of the Enum-Combo Box in Ax 2012?

    I think in active method you need to write code for visible/unVisible and you have to call active method in modified method of the field..

    a)Active()

    {

      visible,unvisible//based on condition

    }

    b)modified()

    {

      super();

      Table_ds,refresh();

      Table_ds.active();

    }

  • Community Member Profile Picture
    on at
    RE: How to change the value of the Enum-Combo Box in Ax 2012?

    okay Martin I will check it.

  • Suggested answer
    Martin Dráb Profile Picture
    235,968 Most Valuable Professional on at
    RE: How to change the value of the Enum-Combo Box in Ax 2012?

    Ah, I see the bug. You use a local buffer CXT_MDrop1, which you never write anything into and therefore it's always empty. Whether it has data or not should have been the very first thing to check in debugger.

    Use the buffer created by your datasource.

  • Community Member Profile Picture
    on at
    RE: How to change the value of the Enum-Combo Box in Ax 2012?

    Hi Martin as you said and since my control is bounded to the data source of the form, I went to the modified() of the field in the form data source and wrote the correct code this time with correct changes but same result. I used the Debugger and observed the values only first case of the switch statement is working for all the values selected from the combo box control. Anything I need to make changes to the properties of the combo box or to the data source field of the form?

  • Verified answer
    Martin Dráb Profile Picture
    235,968 Most Valuable Professional on at
    RE: How to change the value of the Enum-Combo Box in Ax 2012?

    If your control is bound to a datasource, override modified() method of the datasource field instead of selectionChange() of the control.

    If it's unbound, refer to the value of the control and not to a field (CXT_MDrop1.Certificates).

    By the way, this is a typical case when you should use the switch statement instead of if/else.

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
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#2
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans