Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Saturday, May 24, 2014

Look up filter using enum value in Dynamic AX

Hi,

void lookupJobId(FormControl control)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup;
    ;

    //Create an instance of SysTableLookup with the form control passed in
    sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), this);

    //Add the fields to be shown in the lookup form
    sysTableLookup.addLookupfield(fieldnum(InventTable, ItemId), true);
    sysTableLookup.addLookupMethod(tablemethodstr(InventTable, ItemName), false);

    //create the query datasource
    queryBuildDataSource = query.addDataSource(tablenum(InventTable));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(InventTable    ,ABCValue));
    queryBuildRange.value(enum2str(ABC::A)); //Example of Enum value

    //add the query to the lookup form
    sysTableLookup.parmQuery(query);

    // Perform lookup
    sysTableLookup.performFormLookup();
}
/***************************************************************/
If the filter with reference to the enum field already existing in form then.

void lookupJobId(FormControl control)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup;
    ;

    //Create an instance of SysTableLookup with the form control passed in
    sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), this);

    //Add the fields to be shown in the lookup form
    sysTableLookup.addLookupfield(fieldnum(InventTable, ItemId), true);
    sysTableLookup.addLookupMethod(tablemethodstr(InventTable, ItemName), false);

    //create the query datasource
    queryBuildDataSource = query.addDataSource(tablenum(InventTable));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(InventTable    ,ABCValue));
//Direct filter for enum ABC::A
    queryBuildRange.value(enum2str(ABC::A)); //Example of Enum value
//else
//consider the enum fields is stored in header table as HeaderTableName.EnumField
//Make sure that EnumField should be ABC enum

    queryBuildRange.value(enum2str(str2enum(ABC,HeaderTableName.EnumField)));

    //add the query to the lookup form
    sysTableLookup.parmQuery(query);

    // Perform lookup
    sysTableLookup.performFormLookup();
}


Regards,

No comments:

Post a Comment

How find size of recordsortedlist in D365/AX 2012

Hi, This is the continuity of the previous article where we are now getting the size of recordsortedlist . if(recordsortedlist.len() >1) ...