Apparently you cannot populate a form data group runtime in AX. I have been able to overcome the issue by adding the controls dynamically. In this example I have created a form with InventTable as the datasource, and added a FormGroupControl called FormDataGroup with AutoDeclare = Yes. Then I have overridden the executeQuery() on InventTable_ds to call my custom method stored on the form. Here is the source to add AX FormGroupControl runtime from code:
public void WIK_addFieldGroup()
{
#AOT
#Properties
TreeNode fieldGroupRoot = TreeNode::findNode(strFmt('%1\\%2\\Field Groups\\%3',
#TablesPath,
tableStr(InventTable),
tableFieldgroupStr(InventTable, Name)));
TreeNodeIterator tni = fieldGroupRoot.AOTiterator();
TreeNode fieldGroupNode = tni ? tni.next() : null;
int fieldNo;
DictField dictField;
FormControlType controlType;
Object formControl;
formDataGroup.hideIfEmpty(false);
formDataGroup.caption(fieldGroupRoot.AOTgetProperty(#PropertyLabel));
while (fieldGroupNode)
{
fieldNo = (select firstOnly AxId from SysModelElement
where SysModelElement.ParentId == tableNum(InventTable)
&& SysModelElement.ElementType == UtilElementType::TableField
&& SysModelElement.Name == fieldGroupNode.AOTname()).AxId;
dictField = new DictField(tableNum(InventTable), fieldNo);
if (!dictField)
{
// display method in field group
fieldGroupNode = tni.next();
continue;
}
switch (dictField.baseType())
{
case Types::Int64 :
controlType = FormControlType::Int64;
break;
case Types::Integer :
controlType = FormControlType::Integer;
break;
case Types::String :
controlType = FormControlType::String;
break;
case Types::Date :
controlType = FormControlType::Date;
break;
case Types::UtcDateTime :
controlType = FormControlType::DateTime;
break;
//TODO: Implement all field types
}
formControl = formdatagroup.addControl(controlType, strFmt('InventTable_%1', fieldGroupNode.AOTname()));
formControl.dataSource(InventTable_ds.id());
formControl.dataField(fieldNo);
formControl.label(dictField.label());
fieldGroupNode = tni.next();
}
}
