9

I'm trying to get a list of all columns/fields for a list via REST using the /_api/Web/Lists(guid'xxxx')/Fields endpoint. This works fine, except it's adding in all of the system and duplicate fields such as LinkTitle, LinkTitleNoMenu, ContentTypeId, etc.

Short of filtering it out after retrieval using $.grep, is there a way I could use the filter syntax or similar to have SharePoint just return the user columns from a list, i.e. the ones a user might see in an edit or display form?

Thanks!

2
  • 1
    Wouldn't it be better to get the fields from a specific Content Type (/Lists.../ContentTypes/.../Fields)? That is after all what the user would see in a form
    – eirikb
    Commented Feb 26, 2015 at 6:31
  • @eirikb - Maybe. Vadim's answer works well for me but I'll keep this one in mind for future use. I like the idea.
    – Chris Romp
    Commented Feb 27, 2015 at 17:23

4 Answers 4

12

You could apply the following filter to exclude the fields that are not available in List forms:

/_api/web/lists/getbytitle('<list title>')/fields?$filter=Hidden eq false and ReadOnlyField eq false 
1
  • 2
    This worked great. I was attempting to also filter out ContentType and Attachments, but none of the additional filters seemed to work. I can live with just filtering out those two client side. Thanks!
    – Chris Romp
    Commented Feb 27, 2015 at 17:07
1

All system fields in SharePoint have a SourceId of "http://schemas.microsoft.com/sharepoint/v3" defined in their SchemaXml. Any user defined fields will have a Guid. So you can filter using this to return just the user defined ones:

$filter= substringof('SourceID=\"{',SchemaXml)

2
  • Clever. I ended up getting the idea to work with /_api/Web/Lists(guid'xxxx')/Fields?$filter=substringof(%27http://schemas.microsoft.com/sharepoint/v3%27,SchemaXml)%20eq%20false as the URL. Unfortunately it also removed the Title field, which I need.
    – Chris Romp
    Commented Feb 27, 2015 at 17:21
  • Just add an additional filter for Title: &$filter= ((substringof('SourceID=\"{',SchemaXml)) or (Title eq 'Title')) Commented Feb 27, 2015 at 21:08
1

this is working well for me:

/_api/web/Lists(guid '<your list guid here>')/Fields?$select=Title,InternalName&$filter=Hidden eq false and ReadOnlyField eq false and InternalName ne 'Attachments' and InternalName ne 'ContentType'
-1

For instance, My list is like below.

Column1 Column2 Valuea1 Valuea2 Valueb1 Valueb2 Valuec1 Valuec2

Using Rest, If i want to filter a column by its value, Lets say Filter Column1 by the Value 'Valueb1'., then endpoint is

/_api/web/lists/getbytitle('listname')/items?$filter=Column1 eq 'Valueb1'

This will work for One Column only. But if I wanted to include more than one column in such a filtering condition, The EndPoint is

/_api/web/lists/getbytitle('listname')/items?$filter=Column1 eq 'Valuea1’ &$filter=Column2 eq 'Valueb2’

Hope this would help you.

2

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.