After I posted my previous post about new namespaces and methods I got several questions about lookupObjects method from Xrm.Utility namespace. I decided to make additional research to check what was not documented but can be used.
Here is url that contains description of method with standard parameters:
And here is the list and usage of additional parameters that are not documented but can be set using JavaScript:
-
- Lookup form properties:
- disableViewPicker – boolean, when set to “true” disables dropdown with views (default value is “false”)
- disableQuickFind – string, when set to “1” disables “Quick Find Search”
- lookupBrowse – boolean, when set to “true” hides whole section related to search (“Look For”, “Look In” and “Views” dropdown)
- showNew – boolean, when set to “true” adds “New” button to lookup dialog (default value is “false”)
- searchText – string, when populated, passes that value to “Search” field of lookup dialog
- Additional prefiltering – the same possibilities like we have with addPreSearch/addCustomFilter. If you want to use this feature you will have to pass both following parameters – customFilters and customFilterTypes:
- customFilters – array of url-encoded string filters, example –
["%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 – array of strings. When you have one entity or you want to apply the same filter for all available entities just pass [“”], when you have several entities and you want to apply different filters for entities you will have to pass array with names of entities along with array of filters
- example of code for single entity or the same filter for all entities:
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: [""] }; Xrm.Utility.lookupObjects(lookupOptions) .then(function(result){ }) .fail(function(error){ });
- example of code for multiple entities and different filters:
var lookupOptions = { defaultEntityType: "account", entityTypes: ["account", "contact"], 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", "%3Cfilter%20type%3D%22and%22%3E%3Ccondition%20attribute%3D%22firstname%22%20operator%3D%22eq%22%20value%3D%22Andrii%22%20%2F%3E%3C%2Ffilter%3E"], customFilterTypes: ["account", "contact"] }; Xrm.Utility.lookupObjects(lookupOptions) .then(function(result){ }) .fail(function(error){ });
- customFilters – array of url-encoded string filters, example –
- “Related Records Filtering” – filtering of lookup dialog through code settings the same way as it described here through customization:
- allowFilterOff – boolean, when set to “false” disallows user to turn of filtration applied
- filterRelationshipDependantAttribute – string, name of attribute in related entity in format “relatedentityname.attributename”, example – “contact.parentcustomerid”
- filterRelationshipId – Guid, id of relationship
- filterRelationshipName – string, name of relationship used for join
- filterRelationshipType – string, use “1” when want to turn on “Related Records Filtering”
- customViews – array that you can use to add any custom views you want to show in View Picker – the same functionality that you can get using addCustomView method of lookup control. Here is example of usage:
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + " <entity name='contact'>" + " <attribute name='fullname' />" + " <attribute name='createdon' />" + " <attribute name='contactid' />" + " </entity>" + "</fetch>"; var layoutXml = "<grid name='resultset' object='1' jump='productid' select='1' icon='1' preview='1'>" + "<row name='result' id='contactid'>" + "<cell name='fullname' width='150' />" + "<cell name='createdon' width='150' />" + "</row>" + "</grid>"; var customView = { id: "{00000000-0000-0000-0000-000000000001}",//Some fake id recordType: 2,//Entity Type Code of entity... yes, again name: "Custom View Name", fetchXml: fetchXml, layoutXml: layoutXml, Type: 0//Hardcoded, leave it as it is }; var lookupOptions = { defaultEntityType: "contact", entityTypes: ["contact"], allowMultiSelect: false, customViews: [ customView ] }; Xrm.Utility.lookupObjects(lookupOptions) .then(function(result){ }) .fail(function(error){ });
- Lookup form properties:
customFilter not working in chrome or firefox
Hi,
Could this work on Connection Entity’s ‘record2id’ lookup field which looks up to several other entities? I want to restrict them down to only a few entities. Kindly advise.
To be honest I have never tried that but it should work (but no guarantees because I have never tried that).
Andrew
Hi Andrew,
Everthing is working fine but the property showNew: false is not hiding the +New Record button on lookup form.
Can you please help me with the solution.
Thanks,
Shiva
Shiva,
This post is a little outdated. At the moment there is no supported way to hide that button according to the SDK – https://docs.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-utility/lookupobjects
Thanks,
Andrew
Custom filter does not work in UCI.
Hello Yadnyesh,
Methods related to custom filters are not listed as supported so can be considered as unsupported. That explains why methods are not available in the UCI interface.
Andrew
Has anyone noticed that if you use the NEW option that relationship mappings dont work
Bryan,
I believe this is because “context” information is not passed inside lookup window that was opened.
Andrew
Can we Disable or Hide “New” button which is visible in that Quick create/popup ?
Hello Meva,
Unfortunately I don’t know any supported way of doing it.
Thanks,
Andrew
Hi ,
I am trying to use customViews with lookupOptions in new UCI but soemhow it is not working for me.
Note: I am trying to use this on Associate Record button.
I am probably missing something.
Did you tries this with any of your lookupobject
Hello Ankush,
I haven’t tried that with “Associate Record” buttons.
Andrew
Hi Andrew,
Can we Disable or Hide “New” button which is visible in that Quick create/popup with supported or unsupported way ?
I tried with this line of code inside the function that is opening the custom lookup:
$(‘#lookupDialogRoot’, window.parent.document).find(“ul”).css(‘display’, ‘none’);
But doesn’t work.
Best,
Amine,
I’m afraid it’s not doable in supported manner
Andrew.
Andrew,
Can we do it with unsupported manner.
Best,
Amine,
I believe it could be implemented in some way but I don’t know it and I don’t recommend using it.
Andrew
Thanks Andrew for your feedback.
Hi. Custom view is working for me. how can we make display only custom view not all other views along with it?
Hello,
Have you tried to pass an empty array to viewIds?
https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-utility/lookupobjects
Thanks,
Andrew
I tried to use a custom view with that code but the only thing that i have is undefined, theres is a way to use this component with a filter that needs the related entity ?
Hello,
The only way I know now is described here – https://missdynamicscrm.blogspot.com/2014/08/crm-2013-using-addcustomfilter-to-get-filtered-lookup-field-based-on-linked-entity.html
Andrew