Search code examples
axaptax++dynamics-365-operations

How to change command of formcommandbuttonControl dynamically in d365?


I have a form with a formCommandButtonControl in d365. I want to change the command associated to the button dynamically according to the condition in the code. I can't find any base enum to choose the value.

switch (x)
{
case 1:
    formButton.command(New);
break;
case 2:
    formButton.command(DeleteRecord);
break;
}

This is the property in the form enter image description here

How can I choose New and deleteRecord value in x++ code?


Solution

  • Unfortunately, the answer to your question is do not do that and there is no enum.

    When dynamically creating command buttons (FormBuildCommandButtonControl vs FormCommandButtonControl), the Microsoft convention has been to just use a constant (#define.New(260)) and reference that.

    It is unheard of to dynamically change a command button's command and I don't believe it's done anywhere in the system.

    The command button's text most likely won't update dynamically so you'll have change that too.

    You should use a regular button for your purposes or create multiple command buttons and adjust their visibility as needed like the comments say.