Crosssite Lookup Filter

rss

Posted by Hubbaroo - Apr 4 ’14 at 10:38

I have been successfull with cascading the cross site lookups from this link http://formsdesigner.blogspot.com/2013/07/cascading-drop-downs-with-cross-site.html 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 + "')";
}

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 10 years 1 day
    #1 by Dmitry Kozlov Apr 6 ’14 at 06:48

    Of which type is the Category field?

  • Hubbaroo
    Member
    Member for: 10 years 2 days
    #2 by Hubbaroo Apr 7 ’14 at 11:25

    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.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 10 years 1 day
    #3 by Dmitry Kozlov Apr 8 ’14 at 03:31

    [#2]: 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:

    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'";
    }
    
  • Hubbaroo
    Member
    Member for: 10 years 2 days
    #4 by Hubbaroo Apr 9 ’14 at 02:59

    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?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 10 years 1 day
    #5 by Dmitry Kozlov Apr 10 ’14 at 12:45

    [#4]: 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
    Member
    Member for: 10 years 2 days
    #6 by Hubbaroo May 2 ’14 at 05:56

    [#5]: 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

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 10 years 1 day
    #7 by Dmitry Kozlov May 6 ’14 at 04:52

    [#6]: Please, put 'fltr' in quotes:

    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";
    }
    
Displaying 1 to 7 of 7 messages