I have a getItems function that accepts a filter, but I need to know how to pass in two different filters so that I can retrieve items filtered by both Age and First Name.

Here is the definition of the function:

public getItems(list: string, id: string, filters?: string[]): Promise<any[]> {

    let filterStr: string = 'startswith(ContentTypeId,\''+ id +'\')';
      return new Promise((resolve, reject) => {
        let query:any = pnp.sp.web.lists.getById(list).items;
            filters.map((rowFilter: string) => { filterStr += ' and '+ rowFilter; });
                query.filter(filterStr).get().then(Items => {

            }).catch(e => {
  • 1
    What exactly is not working? Are you getting an error or just unexpected results? I don't see anything inherently wrong with the code you have posted, perhaps the problem is in the parameter values you are passing for list, id, or filters? If you can include examples of your parameters in your question we can see where the problem may be.
    – willman
    Commented Feb 26, 2020 at 13:55
  • I wanted to pass two filters in the method.the method can filter only one column and I need to filter by two column first name and age. How i can do it
    – NOOR
    Commented Feb 26, 2020 at 14:18

1 Answer 1


You don't need to change the definition of the getItems function at all. As it is written, you actually have two different options. The way that method is concatenating filter strings together, you can just specify to criteria in a single parameter, for example:

this.getItems(mylistguid, myctid, "firstnamecol eq 'Alice' and agecol eq 27");

But that method is already set up to accept an array of filter strings, and concatenate them together with and's, so you could also call the method with a declared array (e.g. [filterString1, filterString2]) like this:

this.getItems(mylistguid, myctid, ["firstnamecol eq 'Alice'", "agecol eq 27"]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.