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 :
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.

I have the same question (0)
  • Suggested answer
    Miguel Lourenco Profile Picture
    Microsoft Employee on at

    Hi, can you paste the code?

    Is there any business rule as well?

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    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

  • EmployeeOcta Profile Picture
    6 on at

    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
    Miguel Lourenco Profile Picture
    Microsoft Employee on at

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

  • EmployeeOcta Profile Picture
    6 on at

    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
    Pramod M Profile Picture
    1,445 on at

    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

    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

    .

  • Pramod M Profile Picture
    1,445 on at

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

  • Suggested answer
    EmployeeOcta Profile Picture
    6 on at

    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.

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 April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 55 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 37

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans