How to get the form object in a ListPageInteraction class?

maqk picture maqk · Aug 4, 2011 · Viewed 14k times · Source

Working on Microsoft Dynamics AX 2012.

I have a listpage form which has a referenced ListPageInteraction class, just wanted to change the label / caption of a few control. For this I need to do something like:

element.form().design().control('<YourControlName>');

but I cant get this method on the ListPageInteraction class. I have decided to work on the class's initialized method. However there is no way to get to the form from there, how can I get to the controls and set labels?

Answer

wouter picture wouter · Aug 13, 2013

common = this.listPage().activeRecord('Table');
if(common.isFormDataSource())
{
    fds = common.dataSource();
    fds.formRun().control(fds.formRun().controlId('ControlOfScreen')).
       userPromptText('New Description');
}

Another example from projProjectTransListPageInteraction.initializeQuery() perspective changing the label of TransDate field from grid on form projProjectTransactionsListPage

public void initializeQuery(Query _query)
{
    QueryBuildRange     transDateRange;
    // ListPageLabelChange =>
    Common              externalRecord;
    FormDataSource      frmDs;
    FormRun             formRun;
    FormControl         frmCtrl;
    // ListPageLabelChange <=
    ;

    queryBuildDataSource = _query.dataSourceTable(tableNum(ProjPostTransView));
    transDateRange = SysQuery::findOrCreateRange(queryBuildDataSource, fieldNum(ProjPostTransView, TransDate));

    // Date range is [(today's date - 30)..today's date] if not showing transactions for a particular project.
    // Date range is [(dateNull())..today's date] if showing transactions for a particular project so that all transactions are visible.
    transDateRange.value(SysQuery::range(transStartDate, systemDateGet()));

    this.linkActive(_query);

    // ListPageLabelChange =>
    externalRecord = this.listPage().activeRecord(_query.dataSourceTable(tableNum(ProjPostTransView)).name());//No intrisic function for form DS?
    if(externalRecord.isFormDataSource())
    {
        frmDs   = externalRecord.dataSource();
        formRun = frmDs.formRun();
        if(formRun)
        {
            frmCtrl = formRun.design().controlName(formControlStr(projProjectTransactionsListPage,TransDate));
            if(frmCtrl)
            {
                frmCtrl.userPromptText("newName");
            }
        }
    }
    // ListPageLabelChange <=
}