how to get a lookup in the unbound control field:-
internal final class Class1
{
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormControlEventHandler(formControlStr(EcoResProductDetailsExtended, FormStringControl1), FormControlEventType::Lookup)]
public static void FormStringControl1_OnLookup(FormControl sender, FormControlEventArgs e)
{
InventTable inventTable,inventTableLoc;
Query q;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(CustVendExternalItem), sender);
FormRun fr = sender.formRun();
FormDataSource fds = fr.dataSource(formDataSourceStr(EcoResProductDetailsExtended,InventTable));
inventTable = fds.cursor();
q = new Query();
qbds = q.addDataSource(tableNum(CustVendExternalItem));
qbr = qbds.addRange(fieldNum(CustVendExternalItem, ItemId));
qbr.value(inventTable.ItemId);
sysTableLookup.addLookupfield(fieldNum(CustVendExternalItem, Description));
sysTableLookup.parmQuery(q);
sysTableLookup.performFormLookup();
}
}
=========================================
Lookup Code(ranges):-
class EY_DimensionLookUp
{
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormControlEventHandler(formControlStr(OMLegalEntity, CompanyInfo_SubSector2), FormControlEventType::Lookup)]
public static void CompanyInfo_SubSector2_OnLookup(FormControl sender, FormControlEventArgs e)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
SysTableLookup sysTableLookup;
CompanyInfo companyinfo= sender.formRun().dataSource().cursor();
EYDimensionMaster eYDimensionMaster;
sysTableLookup = SysTableLookup::newParameters(tableNum(EYDimensionMaster),sender,true);
queryBuildDataSource = query.addDataSource(tableNum(eYDimensionMaster));
queryBuildDataSource.addGroupByField(fieldNum(eYDimensionMaster, SubSector2));
queryBuildDataSource.orderMode(OrderMode::GroupBy);
queryBuildRange = queryBuildDataSource.addRange(fieldNum(EYDimensionMaster, SubSector1));
queryBuildRange.value(companyinfo.SubSector1);
queryBuildRange = queryBuildDataSource.addRange(fieldNum(EYDimensionMaster, SubSector3));
queryBuildRange.value(companyinfo.SubSector3);
sysTableLookup.addLookupField(fieldNum(EYDimensionMaster, SubSector2 ));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormControlEventHandler(formControlStr(OMLegalEntity, CompanyInfo_SubSector3), FormControlEventType::Lookup)]
public static void CompanyInfo_SubSector3_OnLookup(FormControl sender, FormControlEventArgs e)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange,Qbr;
SysTableLookup sysTableLookup;
CompanyInfo companyinfo= sender.formRun().dataSource().cursor();
EYDimensionMaster eYDimensionMaster;
sysTableLookup = SysTableLookup::newParameters(tableNum(EYDimensionMaster),sender,true);
queryBuildDataSource = query.addDataSource(tableNum(eYDimensionMaster));
queryBuildDataSource.addGroupByField(fieldNum(eYDimensionMaster, SubSector1));
queryBuildDataSource.orderMode(OrderMode::GroupBy);
queryBuildRange = queryBuildDataSource.addRange(fieldNum(EYDimensionMaster, SubSector1));
queryBuildRange.value(companyinfo.SubSector1);
queryBuildRange = queryBuildDataSource.addRange(fieldNum(EYDimensionMaster, SubSector2));
queryBuildRange.value(companyinfo.SubSector2);
sysTableLookup.addLookupField(fieldNum(EYDimensionMaster, SubSector3 ));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormControlEventHandler(formControlStr(OMLegalEntity, CompanyInfo_SubSector1), FormControlEventType::Lookup)]
public static void CompanyInfo_SubSector1_OnLookup(FormControl sender, FormControlEventArgs e)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange,Qbr;
SysTableLookup sysTableLookup;
CompanyInfo companyinfo= sender.formRun().dataSource().cursor();
EYDimensionMaster eYDimensionMaster;
sysTableLookup = SysTableLookup::newParameters(tableNum(EYDimensionMaster),sender,true);
queryBuildDataSource = query.addDataSource(tableNum(eYDimensionMaster));
queryBuildDataSource.addGroupByField(fieldNum(eYDimensionMaster, SubSector1));
queryBuildDataSource.orderMode(OrderMode::GroupBy);
queryBuildRange = queryBuildDataSource.addRange(fieldNum(EYDimensionMaster, SubSector2));
queryBuildRange.value(companyinfo.SubSector2);
queryBuildRange = queryBuildDataSource.addRange(fieldNum(EYDimensionMaster, SubSector3));
queryBuildRange.value(companyinfo.SubSector3);
sysTableLookup.addLookupField(fieldNum(EYDimensionMaster, SubSector1 ));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
}
============================================================================
My requirement is that the lookup data comes from multiple tables, and only unique values are shown.
public void lookup()
{
Query query = new Query();
SysTableLookup sysTableLookup;
QueryBuildDataSource qbds;
super();
sysTableLookup = SysTableLookup::newParameters(tableNum(YNV_CostCenterOwners), this);
sysTableLookup.addLookupField(fieldNum(YNV_CostCenterOwners, BusinessUnitOperatingUnitNumber));
sysTableLookup.addLookupMethod(tableMethodStr(YNV_CostCenterOwners,GetBusinessUnitName));
qbds = query.addDataSource(tableNum(YNV_CostCenterOwners));
qbds.addRange(fieldnum(YNV_CostCenterOwners,BusinessUnitOperatingUnitNumber )).value('!""');
qbds.addSortField(fieldnum(YNV_CostCenterOwners,BusinessUnitOperatingUnitNumber ));
qbds.addOrderByField(fieldnum(YNV_CostCenterOwners, BusinessUnitOperatingUnitNumber));
SysTableLookup.parmUseLookupValue(false); same as SysTableLookup::newParameters(tableNum(), this, true)
qbds.orderMode(OrderMode::GroupBy);
query.allowCrossCompany(True);
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
No comments:
Post a Comment