I am trying to create a lookup in a form to allow users to pick the tableId of a table using UtilIdElements as the source for the lookup. The problem with this is that a record for the table will appear on each layer it exists on, so if a table exists on both sys and cus (which is one of our scenarios) the table entry appears twice in the lookup, when we only want it to show up once. To fix this, I attempted to add group by fields to the lookup and changed the orderMode to OrderMode:GroupBy. When I try to do the lookup after adding the group by, I get this error:
Temporary tables can have either Group By or Order By fields, but not both.
This error doesn't make sense to me, since I am using query objects to generate the lookup, but I'm thinking perhaps that a SQL temporary table is generated during the lookup, thus the error. However, at no point in this code do I explicitly declare any sort fields or change the orderMode to OrderMode:OrderBy, so I am unsure why i am getting this error.
Here is the code for my lookup. The control is of type Int64 to facilitate getting the tableId value. Does anyone have an idea of why this is happening and how I can possibly fix it?
public void lookup()
{
Query query = new Query();
QueryBuildDataSource qbds;
QueryBuildRange typeQBR;
QueryBuildRange tableQBR;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(UtilIdElements), this);
sysTableLookup.addLookupfield(fieldNum(UtilIdElements, Id));
sysTableLookup.addLookupfield(fieldNum(UtilIdElements, Name));
qbds = query.addDataSource(tableNum(UtilIdElements));
qbds.orderMode(OrderMode::GroupBy);
qbds.addGroupByField(fieldNum(UtilIdElements, Id));
qbds.addGroupByField(fieldNum(UtilIdElements, Name));
typeQBR = qbds.addRange(fieldNum(UtilIdElements, recordType));
typeQBR.value(SysQuery::value(UtilElementType::Table));
tableQBR = qbds.addRange(fieldNum(UtilIdElements, Id));
tableQBR.value(con2Str(element.conTableList()));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
// super();
}
Thanks.
Brandt