I am creating another blog here to know how to create table field Id Lookup.
Requirement - Show all VendTable field in lookup.
Solution/Steps
1) Create temprary table as shown in below screen with 2 fields.
Table name - TestFieldsListPreviewTMP
FieldName - use EDT fieldnameShort
FieldId - use EDT Integer
Set Property - TableType = InMemory
Create Primary index on FieldId
2) Create new table TestLookupDSTable for formDatasource where you want to show table field lookup.
Add methods in above table-
Create lookupFields() method to insert all the field list from table buffer.
public static TestFieldsListPreviewTMP lookupCustomFields(Common _common)
{
var dictTable = new DictTable(_common.TableId);
FieldId fieldId = dictTable.fieldNext(0);
TestFieldsListPreviewTMP fieldListPreview;
while (fieldId && ! isSysId(fieldId))
{
fieldListPreview.FieldId = fieldId;
fieldListPreview.FieldName = fieldId2PName(_common.tableId, fieldId);
fieldListPreview.insert();
fieldId = dictTable.fieldNext(fieldId);
}
return fieldListPreview;
}
public static void performLookup(Common _common, FormControl _formControl)
{
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(TestFieldsListPreviewTMP), _formControl);
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
queryBuildDataSource = query.addDataSource(tablenum(TestFieldsListPreviewTMP));
queryBuildDataSource.addSortField(fieldNum(TestFieldsListPreviewTMP, FieldId), SortOrder::Ascending);
sysTableLookup.addLookupfield(fieldnum(TestFieldsListPreviewTMP, FieldId), true);
sysTableLookup.addLookupfield(fieldnum(TestFieldsListPreviewTMP, FieldName));
sysTableLookup.parmQuery(query);
TestFieldsListPreviewTMPfieldListTMP;
fieldListTMP = TestForDataSourceTable::lookupCustomFields(_common);
//TestVend2CustMapping is a form data source table.
sysTableLookup.parmTmpBuffer(fieldListTMP);
sysTableLookup.performFormLookup();
}
//Populate field name
public static FieldName predictFieldName(TableId _tableId, FieldId _fieldId)
{
return fieldId2PName(_tableId, _fieldId);
}
public void modifiedField(FieldId _fieldId)
{
super(_fieldId);
switch(_fieldId)
{
case (fieldNum(TestLookupDSTable,FieldIdVend )) :
this.FieldNameVend = TestLookupDSTable::predictFieldName(tableNum(VendTable), this.FieldIdVend);
break;
default:
}
}
3) Create new form and add TestLookupDSTable as data source and override datasource field lookup method and write below code.
public void lookup(FormControl _formControl, str _filterStr)
{
VendTable vendTable;
TestLookupDSTable::performLookup(vendTable, _formControl);
}
Result -
No comments:
Post a Comment