Wednesday, December 2, 2009

Making independent Form Controls Mandatory or changing labels in code: AX 2009


Here is a quick code snippet to access some features of AX form controls that are not too obvious to get to.
In order to have total access to change whatever you want to AX form controls that are either tied to Datasources or just floating on their own to a form (like a filter), you have to grab the control from the form and set it equal to a form control variable.
In the example below, it is FormStringControl. This is helpful for making something like a combo box that is standalone in the form (like a filter).

FormStringControl formControl;
;
formControl = element.design().controlName('NameOfField');
formControl.label("New Dynamic Runtime label");
formControl.mandatory(true);

You can also use control specific types like FormComboBoxControl but combo boxes are strings and the strings give you more options. Just remember that making a base enum could be a problem as default values for some of these are 0 which is a valid value. Only enums with a starting value of 1 would benefit from something like this as 0 would be an invalid value.

No comments:

Post a Comment