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

Code:
---------

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.relations(true);
        QbdsJoin.joinMode(JoinMode::InnerJoin);
        QbdsJoin.addRange(fieldNum(InventItemInventSetup, ItemId));
        QbdsJoin.addRange(fieldNum(InventItemInventSetup, Stopped)).value(enum2Value(NoYes::No));
        // Set the query to be used by the lookup form
        sysTableLookup.parmQuery(query);

        // 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
        sysTableLookup.performFormLookup();
}




@Rahul Talasila

No comments:

Post a Comment

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...