Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

MSCRM addPresearch function causing an issue

Posted on by

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
    EmployeeOcta 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
    Pramod M 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
    EmployeeOcta 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
    Pramod M 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
    EmployeeOcta 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
    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
    EmployeeOcta 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
    Bipin D365 28,964 Super User 2024 Season 1 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
    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

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