Reputation: 725
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
How can I choose New and deleteRecord value in x++ code?
Upvotes: 0
Views: 1587
Reputation: 18051
The most obvious way is to provide two buttons only showing the relevant.
newButton.visible(x == 1);
deleteButton.visible(x == 2);
Mark the AutoDeclaration attribute of the control.
The code placed in init
or active
method where appropriate.
Upvotes: 0
Reputation: 11544
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.
Upvotes: 1