Page 1 of 1

Cross Site Lookup Sorting

Posted: 21 Mar 2014
by Hubbaroo
I'm having an issue sorting the Cross Site Lookup. Currently it looks up to a list with no problem but I need it to sort by the company name in the lookup. If you could provide an example of how to change the default sort.


Thank you.

Re: Cross Site Lookup Sorting

Posted: 24 Mar 2014
by Dmitry Kozlov
Hello,

Thank you for your request. Please, open Cross-site Lookup Manager and expand the Advanced settings section. In the Request items area you can find SharePoint data requests. Please, modify $orderby clause by replacing Created field with the internal name of the company name field. Here is an example:

Code: Select all

function (term, page) {
  if (!term || term.length == 0) {
    return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id," + 
    "{LookupField}&$orderby=CompanyName&$top=10";
  }
  return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id," +
  "{LookupField}&$orderby={LookupField}&$filter=startswith({LookupField}, '" + term + "')&$top=10";
}

Re: Cross Site Lookup Sorting

Posted: 26 Mar 2014
by Hubbaroo
I start with the following code, the dropdown works as expected, no sorting:

function (term, page) {

if (!term || term.length == 0) {

return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}";

}

return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField}&$filter=startswith({LookupField}, '" + term + "')";

}


I make this change and the dropdown always shows "Searching...":

function (term, page) {

if (!term || term.length == 0) {

return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}"$orderby=Title;

}

return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField}&$filter=startswith({LookupField}, '" + term + "')";

}


The column in the looked-up list is the Title field renamed to Relation. Please help.

Re: Cross Site Lookup Sorting

Posted: 27 Mar 2014
by Dmitry Kozlov
Hi,

It seems, you have a syntax error. Please, try to use the following code:

Code: Select all

function (term, page) {

if (!term || term.length == 0) {

return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby=Title";

}

return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField}&$orderby={LookupField}&$filter=startswith({LookupField}, '" + term + "')";

}
You can open the browser console and find the description of the error there.