var lookupOptions = { defaultEntityType: "account", entityTypes: ["account"], allowMultiSelect: false, customFilters: ["%3Cfilter%20type%3D%22and%22%3E%3Ccondition%20attribute%3D%22name%22%20operator%3D%22eq%22%20value%3D%22test%22%20%2F%3E%3C%2Ffilter%3E"], customFilterTypes: ["account"] }; Xrm.Utility.lookupObjects(lookupOptions) .then(function(result){ }) .fail(function(error){ });
After that, I recalled that I saw the post in the community forum that code works for Classic Interface but doesn’t work in UCI, but I was busy with my project tasks and had no time to troubleshoot so I put that idea aside and forgot about it. Until that same question appeared during the UGSummit.
To assure myself that the code was still valid, I went to the doc.microsoft.com page that describes this method and I discovered that a couple of the new properties were introduced but the most intriguing was the “filter” property. Here is the screenshot from the official documentation:
var lookupOptions = { defaultEntityType: "account", entityTypes: ["account"], allowMultiSelect: false, filters: [{ filterXml: "<filter type='and'><condition attribute='name' operator='eq' value='test' /></filter>", entityLogicalName: "account" }] }; Xrm.Utility.lookupObjects(lookupOptions) .then(function(result){ }) .fail(function(error){ });
The code was refactored, then published, and everything worked fine in UCI, but at the same time stopped working in the Classic Interface.
To make the code function properly again in both interfaces, I suggested to combine both pieces of the code and, depending on the type of the UI used, pass the configuration of the filter that worked for the particular interface. This code uses an undocumented function for detection of the interface type, so please take it in consideration if you want to use that approach or not:
var lookupOptions = { defaultEntityType: "account", entityTypes: ["account"], allowMultiSelect: false }; if (Xrm.Internal.isUci()) { lookupOptions.filters = [{ filterXml: "<filter type='and'><condition attribute='name' operator='eq' value='test' /></filter>", entityLogicalName: "account" }]; } else { lookupOptions.customFilters = ["%3Cfilter%20type%3D%22and%22%3E%3Ccondition%20attribute%3D%22name%22%20operator%3D%22eq%22%20value%3D%22test%22%20%2F%3E%3C%2Ffilter%3E"]; lookupOptions.customFilterTypes = ["account"]; } Xrm.Utility.lookupObjects(lookupOptions) .then(function(result){ }) .fail(function(error){ });
Hi how to hide recent items on the lookup form of web resource
Hello,
Set property disableMru to true – https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-utility/lookupobjects
Andrew
Thanks for your reply, i used the same thing what you have suggested.
For some reason, the property disableMru is not working, after it is set as ‘true’. Tried it in D365 v9.0.5.5 and v9.0.17.
Hello Andrew,
Do you know, how to use linked-entity in filters? I am trying to pull only the team members in the same queue’s team and how how it is not working in UCI. Same thing works fine in older UI.
filters: [{
filterXml:
“” +
“” +
“” +
“” +
“” +
“” +
“” +
“”
,
entityLogicalName: “systemuser”
}],
filters: [{
filterXml:
“” +
“” +
“” +
“” +
“” +
“” +
“” +
“”
,
entityLogicalName: “systemuser”
}],
Hello,
There is no easy way to use linked entities directly. Also your fetchxml is turned to sequence of quotes. Can you please describe your scenario?
Andrew
Hi Andrew!
I also need to build filter for custom lookup based on values in related entity, that is why I need to include link-entity element .
Hello Yaroslav,
You can use AddCustomView method of lookup control to add a custom view that will use link-entity element – https://www.magnetismsolutions.com/blog/zoesands/2018/08/09/lookup-filtering-using-addcustomfilter-vs-addcustomview-in-dynamics-365
Andrew
Thanks for your reply
But I’m not sure that it’s appropriate way for case where I want to use “lookupObject”
I am going to override “Add existing record” button on form subgrid and open custom lookup
Yaroslav,
Got it. Slightly different scenario. In this I would recommend to check my previous post – https://butenko.pro/2017/11/22/microsoft-dynamics-365-v9-0-lookupobjects-closer-look/
There is a way on how you can add a custom view to your lookup – but there is no guarantee that it’ll work because it’s undocumented feature so no guarantees that it’ll work fine in UCI.
What you can do alternatively – get the list of records that will fit your requirement using Xrm.WebApi and fetchxml that utilizes link-entity and use that list in prefiltering that is supported in both interfaces.
Andrew
Second way sounds nice to me!
Thank you, Andrew!
Hi Andrew, good afternoon.
I have a custom html on iframe, that I need to open a lookup view to add price list items (code converts to quotedetail), to add on a quote.
In classic interface works well, but on UCI don’t. I tried your solution to set correct view and it worked.
But i’m having problems on search. It’s like if i type ‘12345’ and i know doesn’t exist, but list continues giving me all records.
What can be?
Thanks!
Hi Felipe,
I had the same problem with searching in a lookup dialog. For a lookup whose view was set to Price list Items in Entity Price List, adding PRODUCT ID column to the view worked for me. Now I can search products.
Hi Andrew!
Have you ever faced with an error “0x80072500 Invalid URI: The Uri string is too long.” in custom lookup window, while using Xrm.Utility.lookupObjects?
Yaroslav,
I have never experienced this issue but I know why you get this error. Parameters that are passed to the lookup dialog are passed through URL and there is a limit to the max length of url – https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
Andrew
Excellent Work…..
Many Thanks…