I have a requirement to pull all the field of Inventtable and store in table to show in Lookup field.First of all we will create a table (TableFieldLookupTmp) that will store all the fields detail of InventTable ?
Lookup Code:
public void lookup()
{
SysTableLookup SysTableLookup;
TableFieldLookupTmp TableFieldLookupTmp;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
Query query = new Query();
tableName tableName = 'Inventtable';
int tmpTableid = tablename2id(tableName),i;
DictField dictField;
DictTable dictTable = new DictTable(tableName2id(tableName));
if(!(select TableFieldLookupTmp where TableFieldLookupTmp.TablenumId == tmpTableid).recid)
{
ttsBegin;
if (dictTable)
{
for (i=1; i<=dictTable.fieldCnt(); i++)
{
dictField = new DictField(dictTable.id(), dictTable.fieldCnt2Id(i));
if(subStr(dictField.name(),0,4) == "DEL_")
continue;
else
{
TableFieldLookupTmp.Label = dictField.label();
TableFieldLookupTmp.field = dictField.name();
TableFieldLookupTmp.TableNumId = tmpTableid;
TableFieldLookupTmp.fieldid = dictField.id();
TableFieldLookupTmp.Types = dictField.baseType();
TableFieldLookupTmp.insert();
}
}
}
else
{
error(strFmt("Table '%1' not found!", tableName));
}
ttsCommit;
}
sysTableLookup = SysTableLookup::newParameters(tableNum(TableFieldLookupTmp), this);
sysTableLookup.addLookupField(fieldNum(TableFieldLookupTmp, label));
sysTableLookup.addLookupField(fieldNum(TableFieldLookupTmp, field),true);
queryBuildDataSource = query.addDataSource(tableNum(TableFieldLookupTmp));
queryBuildDataSource.addSortField(fieldNum(TableFieldLookupTmp, field), SortOrder::Ascending);
queryBuildRange = queryBuildDataSource.addRange(fieldNum(TableFieldLookupTmp, TablenumId));
queryBuildRange.value(int2str(tmpTableid));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
Lookup Code:
public void lookup()
{
SysTableLookup SysTableLookup;
TableFieldLookupTmp TableFieldLookupTmp;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
Query query = new Query();
tableName tableName = 'Inventtable';
int tmpTableid = tablename2id(tableName),i;
DictField dictField;
DictTable dictTable = new DictTable(tableName2id(tableName));
if(!(select TableFieldLookupTmp where TableFieldLookupTmp.TablenumId == tmpTableid).recid)
{
ttsBegin;
if (dictTable)
{
for (i=1; i<=dictTable.fieldCnt(); i++)
{
dictField = new DictField(dictTable.id(), dictTable.fieldCnt2Id(i));
if(subStr(dictField.name(),0,4) == "DEL_")
continue;
else
{
TableFieldLookupTmp.Label = dictField.label();
TableFieldLookupTmp.field = dictField.name();
TableFieldLookupTmp.TableNumId = tmpTableid;
TableFieldLookupTmp.fieldid = dictField.id();
TableFieldLookupTmp.Types = dictField.baseType();
TableFieldLookupTmp.insert();
}
}
}
else
{
error(strFmt("Table '%1' not found!", tableName));
}
ttsCommit;
}
sysTableLookup = SysTableLookup::newParameters(tableNum(TableFieldLookupTmp), this);
sysTableLookup.addLookupField(fieldNum(TableFieldLookupTmp, label));
sysTableLookup.addLookupField(fieldNum(TableFieldLookupTmp, field),true);
queryBuildDataSource = query.addDataSource(tableNum(TableFieldLookupTmp));
queryBuildDataSource.addSortField(fieldNum(TableFieldLookupTmp, field), SortOrder::Ascending);
queryBuildRange = queryBuildDataSource.addRange(fieldNum(TableFieldLookupTmp, TablenumId));
queryBuildRange.value(int2str(tmpTableid));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
quimeVpod-e Don Barker https://wakelet.com/wake/3rj22sFW240bo2kwuGUi-
ReplyDeletevierapounkia