To achieve this I modified the SysQueryForm, specifically the lookup method on the RangeValue field of the Range dataset.
What my code does is use a custom lookup filtered by JournalType.
public void lookup(FormControl _formControl, str _filterStr)
{
SysTableLookup sysTableLookup;
SysDictField sysDictField;
QueryBuildRange rangeJournalType;
Query query;
TmpSysQuery tmpSysQuery;
;
sysDictField = new SysDictField(Range.Table_Id, Range.Field_Id);
if (sysDictField.typeId() == extendedTypeNum(ledgerJournalId))
{
//Search range records for LedgerJournalTable.JournalType so that we can use this to filter the lookup for JournalNum
for (tmpSysQuery = Range_DS.getFirst(); tmpSysQuery; tmpSysQuery = Range_DS.getNext())
{
if (tmpSysQuery.Table_Id == tableNum(LedgerJournalTable) &&
tmpSysQuery.Field_Id == fieldId2Ext(fieldNum(LedgerJournalTable, JournalType), 1))
{
break;
}
}
// If a range value exists for JournalType then perform a filtered lookup of JournalNum
if (tmpSysQuery.RangeValue)
{
sysTableLookup = SysTableLookup::newParameters(tableNum(LedgerJournalTable), _formControl);
sysTableLookup.addLookupfield(fieldNum(LedgerJournalTable, JournalNum));
sysTableLookup.addLookupfield(fieldNum(LedgerJournalTable, JournalName));
sysTableLookup.addLookupfield(fieldNum(LedgerJournalTable, Name));
sysTableLookup.addLookupfield(fieldNum(LedgerJournalTable, JournalType));
query = new Query();
SysQuery::findOrCreateDataSource(query, tableNum(LedgerJournalTable)).addRange(fieldnum(LedgerJournalTable, JournalType)).value(tmpSysQuery.RangeValue);
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
else
{
SysLookup::lookupRange(_formControl, range, sysQueryForm.query());
}
}
else
{
SysLookup::lookupRange(_formControl, range, sysQueryForm.query());
}
}
Hello! I like this code and implemented here in the company, worked well, but if you apply the filter from another table and include the main table in the filter frame and enclose the field in range, then the lookup does not work then displays all records .You know how to solve it? Apply this concept to every relationship 1: n or n: 1 in SysQueyForm form?
ReplyDelete