Thursday, October 16, 2014

Custom LookUp in Ax 2012

Custom LookUp in Ax 2012


Step 1): Create one table with 2 fields Like

              Id

              Name
Fill some data on this table.
Step 2) Create one form and go to designs add one String Edit Control.

Step 3) Go to the methods of stringedit control and override the Lookup Method

Step 4)

Copy and paste the Bellow code and press F5

public void lookup()
{
        SysTableLookup sysTableLookup; // systemclass to create //customlookup
        Query query;
        QueryBuildDataSource qbd;
        ;
        sysTableLookup = SysTableLookup::newParameters(tablenum(LookupTable),this);
           

        // Construct query on the table,
        // whose records you want to show as lookup.
        query = new Query();
        qbd = query.addDataSource(tablenum(LookupTable));
        //qbd.addRange(fieldnum(InventTable,ItemType)).value(SysQuery::value(enum2str(ItemType::Item)));

        // add the fields to the lookup list
        sysTableLookup.addLookupfield(fieldnum(LookupTable,Id));
        sysTableLookup.addLookupfield(fieldnum(LookupTable,Name));

        // pass the query as parameter
        // system will show the records in the lookup
        // as per your query
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();

}

No comments:

Post a Comment