Wednesday, 4 June 2014

EP: DataSetLookup issue with sysDataSetLookup.parmQuery(query)

EP: DataSetLookup issue with sysDataSetLookup.parmQuery(query)

Recently I have faced a strange issue in Dataset lookup method and come to know that there is come issue with " sysDataSetLookup.parmQuery(query) " when it is called from EP.

The actual issue was, when we pass the query as parameter to the method  " sysDataSetLookup.parmQuery(query) ", the query range are not applied and it will fetch all the records without any query filter. It is a strange issue and happens inconsistently.

And I could make out solution for the about issue.
we need to add the range at the end instead of passing it as a parameter, as shown below.

Actual dataset Lookup method:
void dataSetLookup(SysDataSetLookup sysDataSetLookup)
{
    QueryBuildDataSource qbd;
    QueryBuildRange qbr;
   
    List list = new List(Types::String);
    Query query = new Query();

    // Add the table to the query.
    query.addDataSource(tableNum(FCMRooms));

    // Specify the fields to use for the lookup.
    list.addEnd(fieldStr(FCMRooms,RoomName));
    list.addEnd(fieldStr(FCMRooms,RoomType));
    list.addEnd(fieldStr(FCMRooms,InService));

    // Supply the set of lookup fields.
    sysDataSetLookup.parmLookupFields(list);

    // Specify the field that is returned from the lookup.
    sysDataSetLookup.parmSelectField('RoomName');
       
    // Add range
    qbd = query.addDataSource(TableNum(CustTable));
 
    qbr = qbd.addRange(FieldNum(CustTable, AccountNum));
    qbr.value(">=4000"); // Default operator is ==.

    // Pass the query to the SysDataSetLookup so that the query is used.
    sysDataSetLookup.parmQuery(query);
}
Modified  dataSetLookup method:
void dataSetLookup(SysDataSetLookup sysDataSetLookup)
{
    QueryBuildDataSource qbd;
    QueryBuildRange qbr;
   
    List list = new List(Types::String);
    Query query = new Query();

    // Add the table to the query.
    query.addDataSource(tableNum(FCMRooms));

    // Specify the fields to use for the lookup.
    list.addEnd(fieldStr(FCMRooms,RoomName));
    list.addEnd(fieldStr(FCMRooms,RoomType));
    list.addEnd(fieldStr(FCMRooms,InService));

    // Supply the set of lookup fields.
    sysDataSetLookup.parmLookupFields(list);

    // Specify the field that is returned from the lookup.
    sysDataSetLookup.parmSelectField('RoomName');
       
    // Add range
    qbd = query.addDataSource(TableNum(CustTable));
 
    qbr = qbd.addRange(FieldNum(CustTable, AccountNum));
    qbr.value(">=4000"); // Default operator is ==.

    // Pass the query to the SysDataSetLookup so that the query is used.
    sysDataSetLookup.parmQuery().addDataSource(TableNum(CustTable)). value(">=4000");
}



Hope this helps .. Happy Learning.

No comments:

How to Disable “Advanced Filter or Sort” and Enforce Custom Filters on Any D365FO Form

 In Dynamics 365 Finance and Operations, users can apply filters through the “Advanced filter or sort” feature found under the Options tab...