I have a custom form, part of which is displaying the Security roles of users.
I want to be able to filter the roles based on a selected User. To do this I have created a StringEdit control which is not bound to any datasource. I have overridden the lookup() and modified() methods.
The lookup() has this code:
public void lookup()
{
//super();
Query query;
QueryBuildDataSource qbds;
SysTableLookup lookup;
query = new Query();
qbds = query.addDataSource(tableNum(UserInfo));
lookup = SysTableLookup::newParameters(tableNum(UserInfo), this);
lookup.parmQuery(query);
lookup.addLookupfield(fieldNum(UserInfo, Name));
lookup.addLookupfield(fieldNum(UserInfo, Id), true);
lookup.performFormLookup();
}
This is returning the Id value because I want to filter on this.
The modified triggers the executeQuery() method of the main datasource:
public boolean modified()
{
boolean ret;
ret = super();
TmpSecurityRole_DS.executeQuery();
return ret;
}
The executeQuery() method filters the form based on all of the roles (using a custom query here):
public void executeQuery()
{
Query query;
QueryRun queryRun;
QueryBuildDataSource formDataSource;
SecurityRole role;
this.query().dataSourceTable(tableNum(TmpSecurityRole)).clearDynalinks();
this.query().dataSourceTable(tableNum(TmpSecurityRole)).clearLinks();
this.query().dataSourceTable(tableNum(TmpSecurityRole)).clearRanges();
if(UserFilter.valueStr())
{
query = new Query(queryStr(AllSecurityRolesByUser));
query.dataSourceTable(tableNum(SecurityUserRole)).addRange(fieldNum(SecurityUserRole, User)).value(UserFilter.valueStr());
queryRun = new QueryRun(query);
while(queryRun.next())
{
role = queryRun.get(tableNum(SecurityRole), 1);
this.query().dataSourceTable(tableNum(TmpSecurityRole)).addRange(fieldNum(TmpSecurityRole, SecurityRoleAotName)).value(queryValue(role.AotName));
}
}
super();
}
I would like the lookup to display the user name instead of the id which is more presentable.
I looked at Reference Groups but the UserInfo table is a system table so cannot be modified.
Is there a better way?