Search code examples
axaptax++dynamics-ax-2012

Dynamic Field in Form Grid (X++)


Currently I have a table which contains input from users, and these input will be shown in a Form.

The case is, I am able to show checkbox in the form manually but as the input from users grows, I need to have the checkbox to be generated automatically. Is there any way to achieve this in X++?enter image description here

There no restriction whether the checkbox is lined horizontal or vertical, it's just it would be nice if it can be shown as columns.

I wanted to make the checkbox generated automatically so when Table_A have inputs, I don't need to insert a form manually.

This is so when I look at Stall 1, I know what menus it is selling.


Solution

  • As mentioned by FH-Inway, you need to create additional table e.g. Table_ATable_BRelation. Please find below code to add controls dynamically:

    form   = formRun.form();
    design = form.design();
    
    grpCtrl = design.addControl(FormControlType::Group, #GroupControl);    
    
    while select Table_A
    {
        idx++;
    
        Table_ATable_BRelation = this.findOrCreateRelation(Table_A, Table_B);
    
        chkBoxCtrl = grpCtrl.addControl(FormControlType::CheckBox, strFmt("CheckBox%1", Table_A.ID));
        chkBoxCtrl.label(Table_A.Food_Menu);
        chkBoxCtrl.labelPosition(LabelPosition::Above);
        chkBoxCtrl.helpText(strFmt("your text here %1.", Table_A.Food_Menu));
        chkBoxCtrl.value(Table_ATable_BRelation.IsSelling);
    
        chkBoxCtrl.registerOverrideMethod(methodStr(FormCheckBoxControl, clicked),
                                          methodStr(ClassHelper, checkBoxClicked),      
                                          this);
    }
    
    grpCtrl.columns(idx);