How to filter a second LookUp based on a first LookUp value in Class
We can achive this through run base class.
create a class.
In Class declaration:
class custfilter extends RunBase
{
DialogField custid,custgroupid;
Dialog dialog;
CustAccount custaccount;
CustGroupId custgroup;
}
{
DialogField custid,custgroupid;
Dialog dialog;
CustAccount custaccount;
CustGroupId custgroup;
}
Dialog:
protected Object dialog()
{
;
dialog = super();
custgroupid = dialog.addField(extendedTypeStr(CustGroupId));
custid = dialog.addField(extendedTypeStr(CustAccount));
return dialog;
}
{
;
dialog = super();
custgroupid = dialog.addField(extendedTypeStr(CustGroupId));
custid = dialog.addField(extendedTypeStr(CustAccount));
return dialog;
}
getFromDialog:
public boolean getFromDialog()
{
CustGroupId = custgroupid.value();
CustAccount = custid.value();
return super();
}
{
CustGroupId = custgroupid.value();
CustAccount = custid.value();
return super();
}
run:
public void run()
{
super();
}
where dialogCustId is the EDT. let say the name returned at runtime is Fld2_1.
Now if you have to override lookup method of the EDT you can write the method like this
{
super();
}
where dialogCustId is the EDT. let say the name returned at runtime is Fld2_1.
Now if you have to override lookup method of the EDT you can write the method like this
Lookup:
public void Fld2_1_Lookup()
{
SysTableLookup systablelookup;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
Query q;
CustTable ct;
CustGroup cg;
;
if(custgroupid.value())
{
systablelookup = SysTableLookup::newParameters(tableNum(CustTable),custgroupid.control());
systablelookup.addLookupfield(fieldNum(CustTable,AccountNum));
q = new Query();
qbds = q.addDataSource(tableNum(CustTable));
qbds = qbds.addDataSource(tableNum(CustGroup));
qbr = qbds.addRange(fieldNum(CustGroup,custgroup));
qbds.relations(true);
qbds.fetchMode(QueryFetchMode::One2One);
qbr = qbds.addRange(fieldNum(CustGroup,custgroup));
qbr.value(custgroupid.value());
systablelookup.parmQuery(q);
systablelookup.performFormLookup();
}
}
{
SysTableLookup systablelookup;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
Query q;
CustTable ct;
CustGroup cg;
;
if(custgroupid.value())
{
systablelookup = SysTableLookup::newParameters(tableNum(CustTable),custgroupid.control());
systablelookup.addLookupfield(fieldNum(CustTable,AccountNum));
q = new Query();
qbds = q.addDataSource(tableNum(CustTable));
qbds = qbds.addDataSource(tableNum(CustGroup));
qbr = qbds.addRange(fieldNum(CustGroup,custgroup));
qbds.relations(true);
qbds.fetchMode(QueryFetchMode::One2One);
qbr = qbds.addRange(fieldNum(CustGroup,custgroup));
qbr.value(custgroupid.value());
systablelookup.parmQuery(q);
systablelookup.performFormLookup();
}
}
main:
public static void main(Args _args)
{
custfilter custcreate = new custfilter();
if (custcreate.prompt())
{
custcreate.run();
}
}
dialogPostRun
public void dialogPostRun(DialogRunbase dialogs)
{
//;
dialog.dialogForm().formRun().controlMethodOverload(true);
dialog.dialogForm().formRun().controlMethodOverloadObject(this);
//dialog.formRun().controlMethodOverload(true);
//dialog.formRun().controlMethodOverloadObject(this);
//dialog.allowUpdateOnSelectCtrl(true);
//super(dialog);
}
{
custfilter custcreate = new custfilter();
if (custcreate.prompt())
{
custcreate.run();
}
}
dialogPostRun
public void dialogPostRun(DialogRunbase dialogs)
{
//;
dialog.dialogForm().formRun().controlMethodOverload(true);
dialog.dialogForm().formRun().controlMethodOverloadObject(this);
//dialog.formRun().controlMethodOverload(true);
//dialog.formRun().controlMethodOverloadObject(this);
//dialog.allowUpdateOnSelectCtrl(true);
//super(dialog);
}
Calling this class from job:
we can also call the above class from job using this code.
static void Job20(Args _args)
{
custfilter ::main(_args);
}
How to override the event methods on dialog controls?
Overriding the event methods (e.g. modify, validate, selectionChange) on dialog controls is not as straight forward as it is on form controls, but the good news is that it is possible!
In order to override the event methods on dialog controls, the following needs to be done (for simplicity we assume that your class extends RunBase class) :
1) The method dialogPostRun() should be overridden and following two lines are added after the super() call:
_dialog.dialogForm().formRun().controlMethodOverload(true);
_dialog.dialogForm().formRun().controlMethodOverloadObject(this);
This will allow to call the event methods of your class.
2) The actual event methods should be added.
The format of the event method name is as follows: fld<ID>_1_<event name>
Please see the example below.
This method is called whenever a value of the dialog control with ID 900 is modified. In our case it is Employee ID field.
public boolean fld900_1_modified()
{
FormStringControl control = dialog.formRun().controlCallingMethod();
boolean isFieldModified;
;
isFieldModified = control.modified();
// every time the employee id is changed, update the employee name
if(isFieldModified)
{
dlgFldEmplName.value(EmplTable::find(control.text()).Name);
}
return isFieldModified;
}
You will also need to make sure that the control “Employee ID” gets the same control ID as used in the event method name (ID 900). This should be done at the time of adding the control to the dialog. Please see below:
protected Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
{
;
dialog = super(_dialog, _forceOnClient);
// Add a new field by explicitly specifying the field id.
// This field id is used to create the field event methods (e.g. fld900_1_modified()).
dlgFldEmplId = new DialogField(dialog, typeid(EmplId), #dlgFlgEmplIdFieldNo);
dialog.addCtrlDialogField(dlgFldEmplId.name());
dlgFldEmplId.init(dialog);
dlgFldEmplId.label("@SYS81251");
dlgFldEmplId.helpText("@SYS81251");
dlgFldEmplId.value(emplId);
…
}
As you can see the macro #dlgFlgEmplIdFieldNo is used to assign the ID to the dialog control. The macro is defined in the classDeclaration and it equals 900.
That’s all what you need to do to be able to override the events on the dialog controls.
//You can also create a dialog form and pass it as the parameter in the dialog method of runbase class. you can find an example in tutorial_runbase class and form.
https://community.dynamics.com/ax/b/dynamics101trainingcenterax/archive/2015/02/10/runbase-framework-in-microsoft-dynamics-ax-2012
No comments:
Post a Comment