Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to remove items from lookup field

Posted on by 645

I am usimg lookup field and I populate it according to a rule once it populated (for example) with account entity and other time it populate with contact entity, I get the results I need but, if I got 10 results from account and then I changed to contact and got one result I'll see 10 records (9 empty but still shown at the lookup field ans one of the 10 is the result I need) , how to remove these gaps from lookup field using JS?

**more info : the function that populate the lookup is fired from onchange event

I tried to reset the lookup field before I repopulate it but it stays the same:

Xrm.Page.getAttribute("my_lookup_field").setValue(null);

Xrm.Page.getControl("my_lookup_field").getAttribute().setValue(null);

I tried to use :
   Xrm.Page.getControl("my_lookup_field").clearOptions();  - got an exception


*This post is locked for comments

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to remove items from lookup field

    Hi,

    Could you please share your complete code.

    Lookup field bind data dynamically when you click on search icon ,so clearing fields will not clear the list and that's why lookup field does not have clearOptions() property. clearOptions()    used for optionset and not for lookup field.

    I am not sure how do you filtering  the lookup field ? if I am not wrong you are doing old way to filter lookup field. Please check here how to set filter criteria for lookup-

    [View:https://community.dynamics.com/crm/b/crmchap/archive/2017/04/02/more-adventures-in-pre-filtering-customer-lookup-fields-dynamics-crm-dynamics-365-for-enterprise]

    If you are using addpresearch criteria then make sure  you removing presearch criteria for second time filtering  if the filter criteria has changed like below.

    Xrm.Page.getControl("lookupfieldname").removePreSearch(addFilter);

    In addition don't forget to check the record type of lookup might be some data issue as well.

  • Suggested answer
    Prashant_ Profile Picture
    Prashant_ 1,040 on at
    RE: How to remove items from lookup field

    Hi Sahara,

    Which version of dynamics 365 you are using ? because if its  older version 

    Xrm.Page.getAttribute("my_lookup_field").setValue(null); 

    should reset value of lookup if you are using 9.0 version then don't use XRM framework refer following link to update js.
    docs.microsoft.com/.../clientapi-form-context

    If you still facing this issue I suggest you to debug your script. 

    I hope this will help you.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans