control

Refresh AX grid color with displayOption

We have a displayOption implemented for the Vendor transactions screen, which highlights the rows in red color where the posted transactions or the journal has a Document attachment. The requirement was that if we create a new DocuRef entry on the vendor transaction, after closing the DocuView form the grid should change color. In order to refresh AX grid color with displayOption only for the currently selected row we can use the FormDataSource.clearDisplayOption method.

Also there is a great comment on the Dynamics Community about refreshing a set of entries, instead of the current cursor:

https://community.dynamics.com/ax/f/33/t/191245

We have edited \Forms\DocuView\Methods\close as per below to achieve refreshing only the currently highlighted row:

public void close()
{
    FormRun         frm = infolog.parmLastActivatedForm().object();
    FormDataSource  fds;
 
    DocuRef::multiSelectRecordDelete();
 
    SysHelp::initWebBrowser(htmlView);
    curUrl = "";
 
    super();
 
    if (infolog.docu() && infolog.docu().docuView() && infolog.docu().docuView().object())
    {
        infolog.docu().clearDocuView(); //ensure that form is removed from infolog object
    }
 
    if (frm
        && frm.form().name() == formStr(VendTrans))
    {
        fds = frm.dataSource(1);
        fds.clearDisplayOption(fds.cursor());
    }
}
By |2017-02-20T13:32:54+01:00February 20th, 2017|Categories: AX 2012|Tags: , , , , |0 Comments

Add AX FormGroupControl runtime

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();
    }
}

 

By |2016-09-21T12:20:54+02:00September 21st, 2016|Categories: AX 2012|Tags: , , , , |3 Comments

Non-visible fields in the Table browser

As developers and consultants often require the ability to check the content of hidden fields without writing a select statement / query, or taking a quick look in the database for retrieving information, I was wondering if there is a way to do that.

The SysTableBrowser class is using the FormBuildControl.addDataField(int dataSourceId, fieldId fieldId) method for bound and FormBuildControl.addControl(FormControlType controlType, str controlName) as an unbound control. These methods are on kernel level, and they are forcing to hide any bound controls where the field property Visible is set to No.

We can add the hidden fields as extra columns in the SysTableBrowser class with a highlighted color, but as the display grid is tied to the datasource we are using it is not possible to populate it with the right values per record.

(more…)

By |2015-11-23T18:06:51+01:00April 19th, 2010|Categories: AX 2009|Tags: , , , , , , , |2 Comments
Go to Top