web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Apply custom filter to lookups - issue with sorting

(0) ShareShare
ReportReport
Posted on by 4,930

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:

http://www.magnetismsolutions.com/blog/nathaneccles/2013/09/30/crm-2013-javascript-lookup-filtering-using-addcustomfilter

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

}

);

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Sort the Lookup View on Count FIeld. Or Create a new Lookup View with sorting on count field. You can also control the view that should be shown on the form.

  • tpeschat Profile Picture
    4,930 on at

    Thx for your Feedback.

    But since I want to change the filter depending on an option set (product category) on my form, I can only go for the JS approach.

    But there I don't manage the proper sorting.

    br Thomas

  • Suggested answer
    Alagunellaikumar Profile Picture
    6,212 on at

    Hi  Thomas,

    I can't understand, you can apply filter based on the optionset But sorting is going to apply in one column. Am I correct?

    If you want sorting different column based on option set. You will use Plugin Message "Retrieve Multiple" Entity "Product", there you can apply your custom sorting based on the option set filter

  • tpeschat Profile Picture
    4,930 on at

    Hi,

    Based on the optionset Value on the Form I want to dynamically Set the Filter. The Filter is a lookup field to the product entity and is currently sorted by product Name.

    But I want to sort it by another column in the product entity, where I count how often the product has been sold. I tried adding this column to the View used by the lookup field and Order by that column. But it doesn't work

    BR Thomas

  • Suggested answer
    Alagunellaikumar Profile Picture
    6,212 on at

    Hi

    In that case you have to use plugin to sort dynamically.

    Please refer below link

    missdynamicscrm.blogspot.in/.../modify-crm-view-query-or-filter-dynamically-plugin-retrieve-message-crm-csharp.html

  • Verified answer
    tpeschat Profile Picture
    4,930 on at

    Well this was a bug in CRM 2015. Since update to CRM 2016 it works

    thx Thomas

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans