Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Lookup filtering on ONLOAD

(0) ShareShare
ReportReport
Posted on by 244

I am looking for a way to implement to lookup search based on logged in user team in ONLOAD.

I am still looking for a workaround, that can i get control in ONLOAD.

*This post is locked for comments

  • NK Bhairi Profile Picture
    NK Bhairi 244 on at
    RE: Lookup filtering on ONLOAD

    I am looking to filter optionset, based on value in onload.

    one of my function will give Lookupvalue1 as a value. //This is fine

    I need to pass this to other function, something like

    function filterLookup() {

    //new_example is my lookup attribute name (lookup to Batch entity)  on case entity.

       if (Xrm.Page.getControl("new_example") != null ) {

           Xrm.Page.getControl("new_example").addPreSearch(function () {

    // I want to show only one lookup value(Example1) in the new_example. Stck here on where to give the info related to batch

               var fetchQuery = "<filter type='and'><condition attribute='name' operator='like' value='example1%' /></filter>";

               Xrm.Page.getControl("parentaccountid").addCustomFilter(fetchQuery);

           });

       }

    }

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Lookup filtering on ONLOAD

    Hi,

    Try with below code,  make sure you replace the lookup field name and in the fetch xml replace user  field name.

           function OnLoad(executionContextObj) {

               var formContext = executionContextObj.getFormContext();

               if (formContext.getControl("pit_recipient") != null) {

                   formContext.getControl("LookupFieldName").addPreSearch(

                   function () {

                       ApplyLookupFilter(formContext);

                   });

               }

           };

           function ApplyLookupFilter(formContext)

             {

    var userSettings = Xrm.Utility.getGlobalContext().userSettings;

    var userid = userSettings.userId; // get login user id

               var filter = "<filter type='and'>" +

                                       "<condition attribute='UseridfieldName' operator='eq' value='"+ userid+ "' />" +

                                 "</filter>";   // Replace record userid field

               formContext.getControl("LookupFieldName").addCustomFilter(filter);

           };

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans