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.
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.
Could you please post the entire code, I can have look at the code then. It will help to point out what is happening.
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
.
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
Hope this helps.
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.
Probably won't do difference but have you tried using the executionContext instead of Xrm.Page etc?
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.
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.
Hi, can you paste the code?
Is there any business rule as well?
Daivat Vartak (v-9d...
225
Super User 2025 Season 1
Muhammad Shahzad Sh...
106
Most Valuable Professional
Eugen Podkorytov
95