jeudi 29 septembre 2011

How and When to use DisplayOption method on dataSource method

Use the colours in axapta grid is very useful and easy to implement in Microsoft Dynamics AX.


The way to do this, is overriding the displayOption method on the grid's form datasource.
Overriding this method, we can change the background colour and the text colour of the grid lines.
 
This is an example:
We want to paint the invoiced sales orders of SalesTable form in green.

We must override the displayOption method on the SalesTable datasource like this:

public void displayOption(Common _record, FormRowDisplayOption _options)
{
    SalesTable localSalesTable = _record;
    ;


    if(localSalesTable.SalesStatus == SalesStatus::Invoiced)
        _options.backColor(WinApi::RGB2int(50,255,50)); //Green


    super(_record, _options);
}

lundi 19 septembre 2011

How to sort fields in a report

Here is an example to do it, in the report WMSPickingList_OrderPick we have in the fetch method :

  QueryRun                queryRunWMSOrderTrans;

  queryRunWMSOrderTrans = new QueryRun(element.initQueryWMSOrderTrans());



the initQueryWMSOrderTrans method is defined as follows :

Query initQueryWMSOrderTrans()
{
    Query                                 queryWMSOrderTrans;
    QueryBuildDataSource       qbds;
    QueryBuildRange                qbr_status;
    ;

    queryWMSOrderTrans = new Query();
    qbds = queryWMSOrderTrans.addDataSource(tablenum(WMSOrderTrans));

    WMSOrderTrans::queryAddSortDefault(qbds);

    qbr_status  = qbds.addRange(fieldnum(WMSOrderTrans,ExpeditionStatus));
    qbr_status.value(range);

    return queryWMSOrderTrans;
}

the queryAddSortDefault method is defined as follows in the methods of WMSOrderTrans, I needed to sort fields in the report according to Thy_WMSPalletId value : in the ascending order and  Thy_WMSpackageIdBasis field also in the ascending order ( I  have already added these two fields in the table WMSOrderTrans )

// Changed on 19 Sep 2011 at 11:45:07 by iba
static public void queryAddSortDefault(QueryBuildDataSource    _qbS,
                                       OrderMode               _orderMode = OrderMode::OrderBy)
{
    _qbS.sortClear();
    _qbS.orderMode(_orderMode);

    //<iba>
    _qbS.addSortField(fieldnum(WMSOrderTrans, Thy_WMSPalletId),SortOrder::Ascending);
    _qbS.addSortField(fieldnum(WMSOrderTrans, Thy_WMSpackageIdBasis),SortOrder::Ascending);

    //</iba>

    _qbS.addSortField(fieldnum(WMSOrderTrans, RouteId));
    _qbS.addSortField(fieldnum(WMSOrderTrans, IsReserved),SortOrder::Descending);//un-reserved should end up in the bottom

    _qbS.addSortField(fieldnum(WMSOrderTrans, ItemSortCode));
    _qbS.addSortField(fieldnum(WMSOrderTrans, SortCode));
    _qbS.addSortField(fieldnum(WMSOrderTrans, ItemId));

    _qbS.addSortField(fieldnum(WMSOrderTrans, ItemTagging));
    _qbS.addSortField(fieldnum(WMSOrderTrans, CaseTagging));
}

lundi 12 septembre 2011

How to filter displaying data in a grid according to a parameter passed from another form

You need to override the init method of the data source of your form following this way for example:

public void init()
{
    SysDimension        SysDimension;
    ;

    super();

    if( element.args().parm())
    {
        SysQuery::findOrCreateRange(this.query().dataSourceTable(tablenum(Dimensions)), fieldnum(Dimensions, DimensionCode)).value(queryValue(element.args().parm()));
    }
    else
    {
        SysQuery::findOrCreateRange(this.query().dataSourceTable(tablenum(Dimensions)), fieldnum(Dimensions, DimensionCode)).value(queryValue(SysDimension::Department));
    }
}

mardi 6 septembre 2011

How to color records in a grid

Hi

How to color records in a grid is a common user request that can be found on the web.

Follow this link if you need to know how to do it :)