D365FO search in lookup by multiple fields

If you want to make a lookup control on your own dialog or form with functionality for searching by more than one field in lookup, you can do it.

 For example, let's look at how product search works in multiple fields, we can use the PurchTable form and lookup for the ItemId field which allow searching in the lookup by ItemId field and SearchName field depending on your entered value.

By Item number:

By Search name:

To get the same result for your own needs, we need to override the lookup and resolveAmbiguousReference methods
Below is a piece of code for multiple values lookup for an item in dialog control:
...
public Object dialog()
{
    DialogRunbase dialog = super();
    
    dlgItemId = dialog.addField(extendedTypeStr(ItemId));
    dlgItemId.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(MyRunBaseClass, itemIdLookup), this);
    dlgItemId.registerOverrideMethod(methodStr(FormStringControl, resolveAmbiguousReference), methodStr(MyRunBaseClass, itemIdResolveAmbiguousReference), this);
    return dialog;
}
public str itemIdResolveAmbiguousReference(FormStringControl _control) { return FormControlAmbiguousReferenceResolver::resolveAmbiguousReferenceForControl( _control, true, AbsoluteFieldBinding::construct(fieldStr(InventTable, ItemId), tableStr(InventTable)), AbsoluteFieldBinding::construct(fieldStr(InventTable, NameAlias), tableStr(InventTable))); } public void itemIdLookup(FormStringControl _control) { new InventLookup(_control, new Query(), formStr(MyInventItemIdLookup)).run(); }
...

 Also, we need to create a  MyInventItemIdLookup form, which would be a copy of the  InventItemIdLookupPurchase form but with a small difference in the  run method, where we need to remove the condition of the  InventIAmbiguousItemLookupHost implementation. Or you can use the standard purchase form lookup form if you want to add this functionality to your own form, not on dialog, in that caseŠ± you just need to implement the interface  InventIAmbiguousItemLookupHost:

[Form]
public class MyInventItemIdLookup extends FormRun
{
    public void init()
    {
        super();
        element.selectMode(InventTableExpanded_ItemId);
    }
    public void run()
    {
        FormStringControl   callerControl   = SysTableLookup::getCallerStringControl(element.args());
        boolean             filterLookup    = false;
        filterLookup = SysTableLookup::filterLookupPreRun(callerControl,
                                                            InventTableExpanded_ItemId,
                                                            InventTableExpanded_DS);
        super();
                                                  
        SysTableLookup::filterLookupPostRun(filterLookup,
                                            callerControl.text(),
                                            InventTableExpanded_ItemId,
                                            InventTableExpanded_DS,
                                            new FormControlAmbiguousReferenceResolver(
                                                callerControl,
                                                AbsoluteFieldBinding::construct(
                                                    fieldStr(InventTableExpanded, ItemId),
                                                    tableStr(InventTableExpanded)),
                                                AbsoluteFieldBinding::construct(
                                                    fieldStr(InventTableExpanded, NameAlias),
                                                    tableStr(InventTableExpanded))),
                                            InventTableExpanded_NameAlias,
                                            true);
    }
}

The article was written based on knowledge from Microsoft documentation -> Contextual data entry for lookups - Finance & Operations | Dynamics 365 | Microsoft Docs

 

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags