Page 1 of 1

Crosssite Lookup Filter

Posted: 04 Apr 2014
by Hubbaroo
I have been successfull with cascading the cross site lookups from this link http://spform.com/forms-designer- ... office-365 but can't figure out how to apply a simple filter based on text.


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

Re: Crosssite Lookup Filter

Posted: 06 Apr 2014
by Dmitry Kozlov
Of which type is the Category field?

Re: Crosssite Lookup Filter

Posted: 07 Apr 2014
by Hubbaroo
What I would like to accomplish is the Cross Site Lookup connected to the "Comapny List" pulling the "Name". That list has another column called "Catagory". Depending on another choice field where the catagory is selected the filter will apply to the lookup.


I hope that makes sense.

Re: Crosssite Lookup Filter

Posted: 09 Apr 2014
by Dmitry Kozlov
This is my current script:


function (term, page) {
if (!term || term.length == 0) {
var fltr = 'Client'
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Catagory&$orderby=Title&filter=Catagory eq " + fltr;
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Catagory&$orderby={LookupField}&$filter=startswith({LookupField}, '" + term + "') and Catagory eq " + fltr;
}


No errors but the filter is not working. The "Catagory" field on the parent form is a choice field, does that make a differance?

Re: Crosssite Lookup Filter

Posted: 09 Apr 2014
by Hubbaroo
Hello,

Please, make sure that you don't have JS-errors or notifications in the browser console when you expand the lookup drop-down. Try to wrap "Client" into single quotes:

Code: Select all

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

Re: Crosssite Lookup Filter

Posted: 10 Apr 2014
by Dmitry Kozlov
For my sample I've used a choice field too. Please, try to wrap your fltr variable into single quotes as in my sample. Make sure that there are no notifications in the browser console when you expand drop-down.

Re: Crosssite Lookup Filter

Posted: 02 May 2014
by Hubbaroo
Current script:

function (term, page) {
var utype = fd.field('Update_x0020_Type').control().value();
var fltr = ' '
if (utype == 'Opportunity Update') {
fltr = 'Client'
}
if (utype == 'Lead Update') {
fltr = 'Potential Client'
}
if (!term || term.length == 0) {
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Catagory&$orderby=Title&$filter=Catagory eq " + fltr + "&$top=10";
}
return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=Id,{LookupField},Catagory&$orderby={LookupField}&$filter=startswith({LookupField}, '" + term + "')and Catagory eq " + fltr + "&$top=10";
}



The browser console returns this error:

An error has occured during retrieving results. Column 'Client' does not exist. It may have been deleted by another user.


Thank you

Re: Crosssite Lookup Filter

Posted: 06 May 2014
by Dmitry Kozlov
Please, put 'fltr' in quotes:

Code: Select all

function (term, page) {
  var utype = fd.field('Update_x0020_Type').control().value();
  var fltr = ' '
  if (utype == 'Opportunity Update') {
    fltr = 'Client'
  }
  if (utype == 'Lead Update') {
    fltr = 'Potential Client'
  }

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