Crosssite Lookup Filter

Discussions about Cross-site Lookup
Locked
Hubbaroo
Posts: 60
Joined: Sat Sep 21, 2013

04 Apr 2014

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 + "')";
}

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

06 Apr 2014

Of which type is the Category field?

Hubbaroo
Posts: 60
Joined: Sat Sep 21, 2013

07 Apr 2014

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.

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

09 Apr 2014

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?

Hubbaroo
Posts: 60
Joined: Sat Sep 21, 2013

09 Apr 2014

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'";
}

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

10 Apr 2014

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.

Hubbaroo
Posts: 60
Joined: Sat Sep 21, 2013

02 May 2014

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

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

06 May 2014

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";
}

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 9 guests