·
1 min read

Dynamics AX 2012 Enterprise Portal: range on dataSetLookup()

As described here Configuring the Lookup for a Data Set Field [AX 2012] you can change how lookup look like. What you can also do you can range to the lookup to show i.e. only rooms which are in service. Following X++ shows how to achieve this:

void dataSetLookup(SysDataSetLookup sysDataSetLookup)

{

List list = new List(Types::String);

Query query = new Query();

QueryBuildDataSource    queryBuildDataSource;

QueryBuildRange qbr;

 

// Add the table to the query.

queryBuildDataSource  = 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 the range

qbr = queryBuildDataSource.addRange( fieldnum(FCMRooms, InService));

qbr.value(NoYes::Yes);

//if we don’t want user to be able to change range we need to lock it

qbr.status(RangeStatus::Locked);

 

// Pass the query to the SysDataSetLookup so that the query is used.

sysDataSetLookup.parmQuery(query);

}

We need to lock the range in order user is unable to change the range. Otherwise if user in search will specify RoomName “Cubicle 8” (when inService == No) it will still appear because the range will be simply overwritten.