Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

MSCRM addPresearch function causing an issue

(0) ShareShare
ReportReport
Posted on by 6

Hello All Experts,

I have an issue with addpreseaarch.

actually i am calling a function on the onload of the form , which internally calls addpresearch to filter lookup field.

but whenever that lookup is filled with some data and clicked on saved , again that field become dirty.

what could be the best solution for this .

any help will be appreciable.

  • Suggested answer
    EmployeeOcta Profile Picture
    6 on at
    RE: MSCRM addPresearch function causing an issue

    Hello All ,

    Below are the fetchxml before and after

    Before Change:

    fetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"true\">" +

                   "<entity name=\"contact\">" +

                   "<attribute name=\"fullname\" />" +

                   "<attribute name=\"emailaddress1\" />" +

                   "<attribute name=\"mobilephone\" />" +

                   "<attribute name=\"telephone1\" />" +

                   "<attribute name=\"parentcustomerid\" />" +

                   "<attribute name=\"address1_city\" />" +

                   "<order attribute=\"fullname\" descending=\"false\" />" +

                   "<filter type=\"and\">" +

                   "<condition attribute=\"statecode\" operator=\"eq\" value=\"0\" />" +

                   "</filter>" +

                   "<link-entity name=\"connection\" from=\"record2id\" to=\"contactid\" alias=\"de\">" +

                   "<filter type=\"and\">" +

                   "<condition attribute=\"record2objecttypecode\" operator=\"eq\" value=\"2\" />" +

                   "<condition attribute=\"record1id\" operator=\"eq\"  value=\"" +

                   accountId +

                   "\" />" +

                   "</filter>" +

                   "</link-entity>" +

                   "</entity>" +

                   "</fetch>";

    After Change:

    fetchXML = "<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" distinct=\"false\">" +

                   "<entity name=\"contact\">" +

                   "<attribute name=\"fullname\" />" +

                   "<attribute name=\"emailaddress1\" />" +

                   "<attribute name=\"mobilephone\" />" +

                   "<attribute name=\"telephone1\" />" +

                   "<attribute name=\"parentcustomerid\" />" +

                   "<attribute name=\"address1_city\" />" +

                   "<order attribute=\"fullname\" descending=\"false\" />" +

                   "<filter type=\"and\">" +

                   "<condition attribute=\"statecode\" operator=\"eq\" value=\"0\" />" +

                   "</filter>" +

                   "<link-entity name=\"connection\" from=\"record2id\" to=\"contactid\" alias=\"de\">" +

                   "<filter type=\"and\">" +

                   "<condition attribute=\"record2objecttypecode\" operator=\"eq\" value=\"2\" />" +

                   "<condition attribute=\"record1id\" operator=\"eq\"  value=\"" +

                   accountId +

                   "\" />" +

                   "</filter>" +

                   "</link-entity>" +

                   "</entity>" +

                   "</fetch>";

    This after change has resolved my issue.

    i am not sure what it is to be done with distinct as false or true.

  • Pramod M Profile Picture
    1,445 on at
    RE: MSCRM addPresearch function causing an issue

    Could you please post the entire code, I can have look at the code then.  It will help to point out what is happening.

  • EmployeeOcta Profile Picture
    6 on at
    RE: MSCRM addPresearch function causing an issue

    In my case , yes definitely i am filtering records based on customerid lookup.

    but what causing it to not work i am not sure about it.

    after save of the form , what is getting triggered

    .

  • Suggested answer
    Pramod M Profile Picture
    1,445 on at
    RE: MSCRM addPresearch function causing an issue

    The form should not get dirty unless you are changing value inside the lookup or resetting the same value inside the presearch function. Could you please check that if you are setting the lookup field again?

    Here is a link from MS for pre filtering and setting entity types. The last link shows you the old and new way for adding pre filtering.

    docs.microsoft.com/.../setEntityTypes

    docs.microsoft.com/.../addcustomfilter

    www.thrives.be/.../

    Hope this helps.

  • EmployeeOcta Profile Picture
    6 on at
    RE: MSCRM addPresearch function causing an issue

    i have not tried with executionContext .

    but on load event i am triggering two method one is addpresearch and another on is for

    Xrm.Page.getControl("customerid").getAttribute().setLookupTypes(["account"]);

    showing account records only.

  • Suggested answer
    Miguel Lourenco Profile Picture
    on at
    RE: MSCRM addPresearch function causing an issue

    Probably won't do difference but have you tried using the executionContext instead of Xrm.Page etc?

  • EmployeeOcta Profile Picture
    6 on at
    RE: MSCRM addPresearch function causing an issue

    Yes, when code is disabled functionality is working as expected.

    Onload: function ()

    {

    Xrm......addPresearch(addfilter)

    }

    Just a high level idea. Above code is written and function is called on form load.

  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator on at
    RE: MSCRM addPresearch function causing an issue

    Hi,

    SO when you disable addpresearch javascript code which you added on onload is it working as expected?

    Please share source code to investigate this issue further.

    Please Mark My Answer Verified If I Were Helpful

  • Suggested answer
    Miguel Lourenco Profile Picture
    on at
    RE: MSCRM addPresearch function causing an issue

    Hi, can you paste the code?

    Is there any business rule as well?

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106 Most Valuable Professional

#3
Eugen Podkorytov Profile Picture

Eugen Podkorytov 95

Overall leaderboard

Product updates

Dynamics 365 release plans