0

How will I fetch choice field values from site content type directly>

This is what I have tried:

http://<sitecollection>/<site>/_api/web/contenttypes
  • What exactly do you want to fetch? site columns in content type? – Ganesh Sanap Jun 17 at 10:15
  • correct site columns in content type . – Monica Shatani Jun 17 at 10:22
  • Do you want to get the site columns for particular content type or all site columns in your SharePoint site? – Ganesh Sanap Jun 17 at 10:22
  • I have two choice columns in a content type , so i have to fetch the values of these choice columns . – Monica Shatani Jun 17 at 10:22
  • yes , particular content type and this content type is not used in any list or library – Monica Shatani Jun 17 at 10:23
0

If you know the names of your site columns then you can get choices for choice column direct using fields endpoint on web.

/_api/web/fields?$select=Choices&$filter=Title eq 'ChoiceCol'
  • Thank You Ganesh, This Query worked for me as required – Monica Shatani Jun 18 at 8:48
  • Welcome. keep using this platform for any SharePoint related queries. – Ganesh Sanap Jun 18 at 9:20
0

Assuming you know content type ID or title on which you you need find all Choice fields

Query first content type and its fields whose type is choice. Below is example of ContentType Tasks and using filter we are getting only Fields of type Choice

/sites/yoursc/_api/Web/ContentTypes(@v0)/Fields?&@v0='0x0108'&$select=ID,StaticName,Title, TypeAsString&$filter=TypeAsString eq 'Choice'

enter image description here

Now you can loop through above fields to target your specific field with ID. Below is URI for TaskStatus column

 /sites/mysc/_api/Web/AvailableFields(@v0)?&@v0=guid'c15b34c3-ce7d-490a-b133-3f4de8801b76'

You will get output as below

{
    "__metadata": {
        "type": "Collection(Edm.String)"
    },
    "results": [
        "Not Started",
        "In Progress",
        "Completed",
        "Deferred",
        "Waiting on someone else"
    ]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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