Hi,
I applied a custom filter to a lookup field to the product entity on one of my CRM forms, like explained in the follwing example:
Unfortunately I didn't find out how to configure sorting of this lookup field, since the results are always sorted alphabetically, although I want to have them sorted according one lookup field (which counts how often this product has been sold).
I already tried:
- adding orderby to the filter criteria (which Looks correct in debugging Information)
- adding the Count column + order by in the lookup view
Both didn't help.
AND the filter is only applied to the lookup field, but not to the view, which is opened if you click on "add more".
Maybe you can help me out with this issue?
thx in advance
Thomas
This is my code to apply the filter:
var parentfilter = '';
var crm_url = Xrm.Page.context.getClientUrl();
if (crm_url == "xxxx") {
parentfilter = "{xxx some GUID xxx}";
}
else {
parentfilter = "{xxx some GUID xxx}";
}
SDK.REST.retrieveMultipleRecords(
"Product", // Entität für die die Suche ausgeführt wird
"$select=ProductId, Name&$filter=ParentProductId/Id eq (guid'" + parentfilter + "')", // Definition der Suche
// Results handler
function (retrievedProducts) {
//create a filter xml
var filter =
"<filter type='and'>" +
"<condition attribute='productid' operator='in'>";
for (var i = 0; i < retrievedProducts.length; i++) {
var Product_Name = retrievedProducts[i].Name;
var Product_Id = retrievedProducts[i].ProductId;
filter += "<value uiname='" + Product_Name + "' uitype='Product'>{" + Product_Id + "}</value>";
}
filter += "</condition>" + "</filter>";
function addFilter() {
//add filter
Xrm.Page.getControl("xxx lookup field xxx").addCustomFilter(filter);
}
// Filter für Lookup Feld "Kunde" Setzen
Xrm.Page.getControl("xxx lookup field xxx").addPreSearch(addFilter);
},
// Error handler
function errorCallBack(error) {
alert(error.message);
},
//On complete handler
function retriveRecordsComplete() {
// provide success message
}
);