Page 1 of 1

Filter documentset folder by contenttype

Posted: 14 Sep 2018
by jacob
Hi,

I'm trying to create a lookup field to only show the documentset folders by it's contenttype and not the documents inside the folder. However, it shows me everything. Any idea what i'm doing wrong?

Code: Select all

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

Re: Filter documentset folder by contenttype

Posted: 18 Sep 2018
by AlexZver
Hi jacob,

Please, use the following code for this issue:

Code: Select all

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

Re: Filter documentset folder by contenttype

Posted: 18 Sep 2018
by jacob
Hi AlexZver,

That worked. Thank you very much!