0

I'm trying to validate whether a list has an specific list of fields, it keeps returning all the existing fields from the list, how do I make this things work? Is there a better way to achieve what I'm trying?

sp.web.lists.getByTitle("SliceBox").fields.select("Title","Body","Link","Picture","Visible").get()
    .then( (fields: any[]) => {
        console.log("> number of fields returned:", fields.length);

        fields.forEach(f => {
            console.log("> field:", f);
        })              
    })
    .catch( err => {
        console.log("> fields failure: ", err);
});
Mr. Dr. Sushi
  • 469
  • 8
  • 22

1 Answers1

1

We will have to use 'filter' in above scenario

 sp.web.lists.getByTitle("SliceBox").fields.filter("((Title eq 'Title') or (Title eq 'Body'))").get()

We can include more 'or' for more filters. When we use 'select', it only return those selected properties within that field. Means, if we use select('Title') it will only return 'Title' property of all fields.

get2pallav
  • 64
  • 3