SharePoint / PnP-JS-Core

Code moved to https://github.com/pnp/pnpjs. This repository is archived.
Other
379 stars 231 forks source link

How to filter list Items with more than one Lookup field values?? #793

Closed ahsanranjha closed 6 years ago

ahsanranjha commented 6 years ago

Example; how to write filter for more than one fields or more than one values

var filter = 'VisaStatus eq \'1\' or 'VisaStatus eq \'1\';

koltyakov commented 6 years ago

I would recommend SharePoint REST API and OData operations reference. PnPjs library, in most cases, mirrors REST API functionality and always ends up with a REST requests sent over the wires.

In regards to filtering based on lookup values:

A lookup field entity name ends with 'Id' suffix. Conditions can be combined with 'OR' or 'AND' operators. Round braces can be used. Multi-value lookups are filtered the same way as a single value lookup fields.

// Selects items which have `SingleValueLookup` lookup fields populated with items with ID 1 or 2 
items.filter(`SingleValueLookupId eq 1 or SingleValueLookupId eq 2`).get().then(console.log);

// Selects items which have `MultiValueLookup` lookup fields populated with items with ID 2 and 3
items.filter(`MultiValueLookupId eq 2 and MultiValueLookupId eq 3`).get().then(console.log);

// Selects items which have `SingleValueLookup` lookup fields populated with items with Title 'Item title' 
items.filter(`SingleValueLookup/Title eq 'Item title'`).get().then(console.log);
ahsanranjha commented 6 years ago

Thanks you koltyakov :)