Thursday, October 5, 2017

Filters Across Multiple Fields in Grid Control (AX 2012)

//Form Method

public boolean filterItems(str 200 _itemSearch)
{
    #Define.LogicalOr("||")

    str fieldMatchTemplate = '(%1.%2 like "%3")';

    Query query;
    QueryBuildDataSource qbds;
    QueryFilter qf;

    FormStringControl control;
    FormDataSource dataSource;
    int controlCount;
    int controlIndex;

    str searchString;
    str whereClause;
    container whereClauseCon;

    boolean success;

    if (lastSearchItem != _itemSearch)
    {
        lastSearchItem = _itemSearch;
query = new query(queryStr(ProductLookup));

  if (strLen(_itemSearch) > 0)
        {
            searchString = SysQuery::valueLikeAfter(SysQuery::value(_itemSearch));

            controlCount = Grid.controlCount();
            for (controlIndex = 1; controlIndex <= controlCount; controlIndex++)
            {
                control = Grid.controlNum(controlIndex);

                if (control.visible() == true)
                {
                    dataSource = control.dataSourceObject();

                    if (dataSource != null)
                    {                       
                        whereClause = strFmt(fieldMatchTemplate,dataSource.name(),
                            control.dataFieldName(),searchString);
                        whereClauseCon += whereClause;
                    }
                }
            }

            whereClause = con2Str(whereClauseCon, #LogicalOr);

            qbds = query.dataSourceTable(tableNum(InventTable));
           //below logic for query range
          //Todo
        }
        else
        {
            searchString = SysQuery::valueUnlimited();
        }

        // Set the query on the form and execute it
        InventTable_ds.query(query);
        InventTable_ds.executeQuery();
    }

    return success;
}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...