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();
}
}
[…] post Add AX FormGroupControl runtime appeared first on DAXRunBase blog by Vilmos […]
HI Vilmos,
Thanks for posting this,
I am try to do the same in my environment and successful to add formgroup control dynamically at runtime but Fields are growing multiple times when i refresh the form .
For example , my fieldGroup has 3 fields so when i open form it has 3 fields in formGroupControl but when i refresh form (by F5 or some filter) then addtional same 3 fields are created means now form has 6 fields and so on ..
Please suggest
Declare a new global boolean variable in the form’s Classdeclaration like isFieldGroupAdded. By default, it will have false state. Put the dynamic field group logic in a code block like if (!isFieldGroupAdded) { … }, and at the end of the logic set isFieldGroupAdded = true;
This way it will only fire your logic once.