Lookup filter in Ax 2012 R3
sub:Lookup fields filter based on the parent lookup using UiBuilder.
UiBuilder class:
class LookUpFilterUiBuilder extends SysOperationAutomaticUIBuilder{
//Author : Rajaram E
//Title : Lookup fields filter based on the parent lookup using UiBuilder.
DialogField dlgBusinessGroup;
DialogField dlgBranch;
UiBuilderContract contract;
}
{
// build ui
Dialog dialogLocal = this.dialog();
contract = this.dataContractObject();
this.addDialogField(methodStr(UiBuilderContract,parmBusinessGroup), contract);
this.addDialogField(methodStr(UiBuilderContract,parmBranch), contract);
}
public void businessGroupLookup(FormStringControl _formStringControl)
{
Query query = new Query();// query
SysTableLookup sysTablelookup;// lookup
sysTableLookup = SysTableLookup::newParameters(tableNum(OMHierarchyType),_formStringControl);
sysTableLookup.addLookupfield(fieldNum(OMHierarchyType,Name));
query.addDataSource(tableNum(OMHierarchyType));// adding table in query
sysTableLookup.ParmQuery(query); // run query
sysTableLookup.PerformFormLookup();// enable lookup
}
public boolean businessGroupModified(FormStringControl _control)
{
// while modified to be related tavle should be clear
dlgBusinessGroup.value(_control.valueStr());
dlgBranch.value('');
return true;
}
// branch method
public void organizationvaluelookup(FormStringControl _formStringControl)
{
Query query = new Query();
SysTableLookup sysTablelookup;
QueryBuildDataSource Qbds, Qbds1, Qbds2;
QueryBuildRange queryBuildRange;
;
sysTableLookup = SysTableLookup::newParameters(tableNum(OMOperatingUnit),_formStringControl);// lookup table and fields
sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit,OMOperatingUnitNumber),true);// this is the parameter field
sysTableLookup.addLookupfield(fieldNum(OMOperatingUnit,Name));// display name
Qbds = query.addDataSource(tableNum(OMOperatingUnit));// adding first table in the query
Qbds1=Qbds.addDataSource(tableNum(OMHierarchyRelationship));//adding second datasource inside first datasource
Qbds1.joinMode(JoinMode::InnerJoin);// join
Qbds1.addLink(fieldNum(OMOperatingUnit, RecId), fieldNum(OMHierarchyRelationship, ChildOrganization));// relationship for both table
Qbds2=Qbds1.addDataSource(tableNum(OMHierarchyType));// adding thired table
Qbds2.joinMode(JoinMode::InnerJoin);// join mode
Qbds2.addLink(fieldNum(OMHierarchyType,RecId), fieldNum(OMHierarchyRelationship,HierarchyType));// relationship
Qbds2.addRange(fieldNum(OMHierarchyType,Name)).value(dlgBusinessGroup.value());//adding range value from first lookup based
sysTableLookup.ParmQuery(query);
sysTableLookup.PerformFormLookup();
}
public void getFromDialog()
{
contract = this.dataContractObject();
super();
}
public void postRun()
{
super();
}
public void initializeFields()
{
contract = this.dataContractObject();
}
public void postBuild()
{
super();
// business group
dlgBusinessGroup = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(UiBuilderContract, parmBusinessGroup));
if (dlgBusinessGroup)
{
dlgBusinessGroup.lookupButton(2);
}
dlgBusinessGroup.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(LookUpFilterUiBuilder, businessGroupLookUp), this);
dlgBusinessGroup.registerOverrideMethod(methodStr(FormStringControl, modified), methodStr(LookUpFilterUiBuilder, businessGroupModified), this);
// branch
dlgBranch = this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(UiBuilderContract,parmBranch));
dlgBranch.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(LookUpFilterUiBuilder, organizationvaluelookup), this);
if (dlgBranch)
{
dlgBranch.lookupButton(2);
}
}
No comments:
Post a Comment