Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Filter lookup based on optionset in form

Posted on by Microsoft Employee

Hi,

I want to filter a lookup on form using Optionset. I tired using addcustomfilter but nothing worked. "filter" is event being called onload event

function filter (executionContext) {

// get the form context

formContext = executionContext.getFormContext();
formContext.getControl("new_lookup").addPreSearch(filterCustomerAccounts);
}

function filterCustomerAccounts() {

var option = formContext.getControl("new_options").getValue();
if (option = 100000001) {
var customerAccountFilter = "<filter type='and'><condition attribute='telephone1' operator='begins-with' value='55'/></filter>";
formContext.getControl("new_lookup").addCustomFilter(customerAccountFilter, "account");
}
else {
var customerAccountFilter = "<filter type='and'><condition attribute='name' operator='begins-with' value='T'/></filter>";
formContext.getControl("new_lookup").addCustomFilter(customerAccountFilter, "account");

}


}

*This post is locked for comments

  • Suggested answer
    Charles Abi Khirs Profile Picture
    Charles Abi Khirs 3,569 on at
    RE: Filter lookup based on optionset in form

    Hello,

    Check this post: charlesak.blogspot.com/.../crmd365-filter-lookup-based-on-nn.html

    You can change the filter criteria as per your need.

  • Inogic Profile Picture
    Inogic 24,094 on at
    RE: Filter lookup based on optionset in form

    Hi Mudassar Hassan,

    Provided code looks  correct . Please do following two things :-

    1. Replace the highlighted  statement with 

    var option = formContext.getAttribute("new_options").getValue();

    3326.form.png

    1. Register your filter function on onchange event of your optionset field.

     

    You can refer the link:- https://www.inogic.com/blog/2015/08/apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script/

    Hope it helps.

    Thanks!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Filter lookup based on optionset in form

    yes I already checked, no error and executes well. but while applying filters there is no change

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Filter lookup based on optionset in form

    Can you check developer console (F12) for any errors? If any share it here.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Filter lookup based on optionset in form

    Yes it is configured on the load. But it is not working. when i change the value on the option set, filter doesnt apply on the lookup accordingly

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Filter lookup based on optionset in form

    Hi,

    You code looks okay. Have you registered it on load? What is not working? Are you getting any error? Did you try to debug your script?

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