web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How can I search by multiple fields in a lookup in D365FO?

(5) ShareShare
ReportReport
Posted on by 32

Hi everyone,

 

I'm trying to enable searching by multiple fields in a lookup in Dynamics 365 Finance and Operations, but I can't get it to work as expected.

 

Currently, the lookup only searches by the YuklemeYeriKoduStr field, but I also want it to search by the YuklemeYeriAdi field. I’ve tried using resolveAmbiguousReference and setting both fields, but the lookup still only filters by the first one.

 

Here is the relevant part of my code for the data field:

 

 [DataField]
 class YuklemeYeriKoduStr 
 {
     /// <summary>
     ///
     /// </summary>
     /// <param name = "_formControl"></param>
     /// <returns></returns>
     public str resolveAmbiguousReference(FormControl _formControl)
     {
         return FormControlAmbiguousReferenceResolver::resolveAmbiguousReferenceForControl (
 _formControl,
 true,
             AbsoluteFieldBinding::construct(fieldStr(YuklemeYeri, YuklemeYeriKoduStr),tableStr(YuklemeYeri)),
             AbsoluteFieldBinding::construct(fieldStr(YuklemeYeri, YuklemeYeriAdi),tableStr(YuklemeYeri)));
     }
     /// <summary>
     ///
     /// </summary>
     /// <param name = "_formControl"></param>
     /// <param name = "_filterStr"></param>
     public void lookup(FormControl _formControl, str _filterStr)
     {
         new InventLookup(_formControl, new Query(), formStr(YuklemeYeriLookup)).run();
     }
 }
 
 
 
And here is the code for the lookup form:
 
 
[Form]
public class YuklemeYeriLookup extends FormRun
{

    public void run()
    {
        FormStringControl lookupHostControl = SysTableLookup::getCallerStringControl(this.args());
        boolean isFiltered = SysTableLookup::filterLookupPreRun(lookupHostControl, YuklemeYeri_YuklemeYeriKoduStr, YuklemeYeri_ds);
        super();
        SysTableLookup::filterLookupPostRun(
        isFiltered,
        lookupHostControl.text(),
        YuklemeYeri_YuklemeYeriKoduStr, 
        YuklemeYeri_ds,
        new FormControlAmbiguousReferenceResolver(lookupHostControl),
        YuklemeYeri_YuklemeYeriAdi );
    }
}
 
 
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at
    Check out Contextual data entry for lookups first to understand how the feature works.
     
    Moved from Integration, Dataverse, and general topics forum to Finance | Project Operations, Human Resources, AX, GP, SL forum.
  • Ahmet Enes Profile Picture
    32 on at
    Thanks for your response.
    I’ve already reviewed the "Contextual data entry for lookups" documentation and tried the suggested steps, even experimented with a few variations, but unfortunately I still couldn’t achieve the desired result.
  • udaY-ch Profile Picture
    5,173 on at
    Hi
     
    Please find the reference belwo from AssetId look on the PurchTable form,
     
    Ref: AssetInvoiceLookup.run method
     public void run()
     {
         FormStringControl   formStringControl = SysTableLookup::getCallerControl(element.args()) as FormStringControl;
         boolean             filterLookup;
    
         canClose = true;
    
         if (formStringControl)
         {
             filterLookup = SysTableLookup::filterLookupPreRun(formStringControl, assetTable_AssetId, assetTable_ds);
    
             super();
    
             SysTableLookup::filterLookupPostRunEx(
                 filterLookup,
                 formStringControl.text(),
                 assetTable_AssetId,
                 assetTable_ds,
                 AssetDataInteractorFactory::useExistingOrCreateResolver(formStringControl),
                 assetTable_Name);
         }
         else
         {
             super();
         }
     }
     
    Please do use insert code snippet for code alignment. 
     
    If you found this answer helpful, please mark it as the verified solution. This helps others in the community find answers quickly. Thank you!
     
    Thanks
    Uday
     
  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at
    @Ahmet Enes Can you give us more details about your implementation? For instance, what are title fields of your table? Do you have indexes for both fields?
  • Ahmet Enes Profile Picture
    32 on at

    Thanks for your response.

    The field I'm displaying on the form is an ID field. I want to create a lookup for this field that shows both the ID and the string field from another table. When the user types a value into the field, the lookup should display filtered results based on the string value. Once the user selects an entry, the corresponding ID should be stored in the background.
  • Verified answer
    Ahmet Enes Profile Picture
    32 on at
    Hello, I solved my problem.
     
    First of all, I want to thank everyone who helped me.
     
    The code I wrote in my form :
    [Control("String")]
     class IhracatDosyaBilgileri_SevkYeriKoduStr
     {
     public void lookup()
     {
     SevkYeri::lookupSevkYeri(this);
     } 
    }
     
     
    The code I wrote in my table :
     
    public static void lookupSevkYeri( FormControl _ctrl)
     {
      Args args; FormRun formRun;
      FormStringControl formStringControl;
      args = new Args();
      args.name(formStr(SevkYeriLookup));
      args.caller(_ctrl);
      formRun = classfactory.formRunClass(args);
      formRun.init();
      if (_ctrl is FormStringControl)
      {
       formStringControl = _ctrl as FormStringControl;
       formStringControl.performFormLookup(formRun);
      } 
     else 
     {
       throw error(Error::wrongUseOfFunction(funcName())); 
     }
    }
    The code I wrote in my lookup form :
     
     
    [Form]
    public class SevkYeriLookup extends FormRun
    {
        boolean         canClose;
    
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public boolean canClose()
        {
            boolean ret;
        
            ret = super() && canClose;
        
            return ret;
        }
    
        /// <summary>
        ///
        /// </summary>
        public void init()
        {
            super();
            element.selectMode(SevkYeri_SevkYeriKoduStr);
        }
    
        public void run()
        {
            FormStringControl   callerControl = SysTableLookup::getCallerControl(element.args()) as FormStringControl;
            boolean             filterLookup;
    
            canClose = true;
    
            if (callerControl)
            {
                filterLookup = SysTableLookup::filterLookupPreRun(callerControl, SevkYeri_SevkYeriKoduStr, SevkYeri_ds);
                super();
    
                SysTableLookup::filterLookupPostRunEx(
                filterLookup,
                callerControl.text(),
                SevkYeri_SevkYeriKoduStr,
                SevkYeri_ds,
                new FormControlAmbiguousReferenceResolver(
                    callerControl,
                    AbsoluteFieldBinding::construct(fieldStr(SevkYeri, SevkYeriKoduStr), tableStr(SevkYeri)),
                    AbsoluteFieldBinding::construct(fieldStr(SevkYeri, SevkYeriAdi), tableStr(SevkYeri))
                ),
                SevkYeri_SevkYeriAdi);
            }
            else
            {
                super();
            }
        }
    
    }
     
    My Notes : 
     
    If you encounter an error, please check whether there is an index on the fields you are trying to search in your table
     
  • Suggested answer
    DAnny3211 Profile Picture
    11,417 Super User 2026 Season 1 on at

    Hi Ahmet,


    Thanks for sharing your code and explanation. To enable searching by multiple fields in a lookup in D365FO, your approach using resolveAmbiguousReference is on the right track. However, the lookup behavior also depends on how the filtering is applied in the lookup form itself.

     

    In your YuklemeYeriLookup form, you're currently filtering only by YuklemeYeriKoduStr. To support multiple fields, you can enhance the filtering logic by including both YuklemeYeriKoduStr and YuklemeYeriAdi in the pre-run and post-run filtering steps.

     

    Here’s a suggestion:

     

    • In the filterLookupPostRun method, ensure that both fields are considered in the filter expression.

    • You might also need to customize the query used in the lookup to include a WHERE clause that checks both fields using LIKE or similar logic.


    •  
     

    Additionally, make sure that the FormControlAmbiguousReferenceResolver is correctly configured to resolve both fields, and that the lookup form’s data source supports filtering on both columns.

     

    Please verify if this response was helpful.

     

    Thanks and best regards,

    Daniele

    Note: This response was prepared with support from Copilot to ensure clarity and completeness.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans