Wednesday, 15 April 2015

Filter Records on Item Lookup Through X++ - Ax 2012

Hello Guys ..!

Here i'm sharing code for filtering records in a look up. In this example I'm filtering the items which are stopped and displaying only available  items.

Write the below code in formDatasource ->Field->methods-> Override LookUp() method


public void lookup(FormControl _formControl, str _filterStr)
       // super(_formControl, _filterStr);
        Query query = new Query();
        QueryBuildDataSource qbds;
        QueryBuildDataSource QbdsJoin;

        // Instantiate sysTableLookup object using table which will provide the visible fields
        SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(InventTable), _formControl);

        // Create the query.
        qbds= query.addDataSource(tableNum(InventTable));
        qbds.addRange(fieldNum(InventTable, ItemId));

        //Join Table
        QbdsJoin= qbds.addDataSource(tableNum(InventItemInventSetup));
        QbdsJoin.addRange(fieldNum(InventItemInventSetup, ItemId));
        QbdsJoin.addRange(fieldNum(InventItemInventSetup, Stopped)).value(enum2Value(NoYes::No));
        // Set the query to be used by the lookup form

        // Specify the fields to show in the form.
        sysTableLookup.addLookupfield(fieldNum(InventTable, ItemId), true);
        sysTableLookup.addLookupfield(fieldNum(InventTable, NameAlias), true);
   sysTableLookup.addLookupMethod(tablemethodstr(InventTable, Alle_Unit));
   sysTableLookup.addLookupfield(fieldNum(InventTable, ItemType),true);
        // Perform the lookup

@Rahul Talasila

No comments:

Post a Comment

Foreign currency revaluation currencies not showing in drop down in dynamics 365 finance & Operations 8.0

In the previous versions you can see all currency codes in the currency drop down, but Dynamics 365 finance and operations 8.0 you don'...