Applying range on the lookup based on the selection of value on other field X++
Views (403)
Hi folks,
Since, I have been working on Dynamics 365 Finance and Operations development for a while. I would like to share some important tips and tricks related to D365 FO development.
I had been given a scenario where I needed to show a filtered value based on the selection of value on the other field.
Since, you guys are already familiar on how to create lookups in Dynamics AX 2012 by overriding lookup method. In D365, there is a slight change in creating lookups in standard objects because overlayering is no more allowed.
You need to first create form extension class.
[ExtensionOf(formStr(MarkupTrans))]
final class MarkupTransForm_Extension
{
}
// Right click and copy the event handler method signature, paste it in your extension class and then write the logic below:// Added a custom field "Charges categories" in MarkupTable which is used for setting Charges codes. Lookup values of Charges codes will be populated based on the selection // of Charges categories that are setup in Charges code setup form.
[FormControlEventHandler(formControlStr(MarkupTrans, MarkupTrans_MarkupCode), FormControlEventType::Lookup)]
public static void MarkupTrans_MarkupCode_OnLookup(FormControl sender, FormControlEventArgs e)
{
FormRun element;
FormControl formCtrl;
Query query;
QueryBuildDataSource markupTrans;
SysTableLookup sysTableLookup;
element = sender.formRun();
formCtrl = element.design().controlName(formControlStr(MarkupTrans, ChargesCategory));
sysTableLookup = SysTableLookup::newParameters(tableNum(MarkupTable), sender);
query = new Query();
markupTrans = query.addDataSource(tableNum(MarkupTable));
sysTableLookup.addLookupfield(fieldNum(MarkupTable, MarkupCode));
//below code is used to get the filtered lookup based on the other field value.
markupTrans.addRange(fieldNum(MarkupTable, ChargesCategory)).value(formCtrl.valueStr());
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs;
event.CancelSuperCall();
}

Like
Report
*This post is locked for comments