JSOM: Get all content types from SharePoint web

The code snippet which helps to get the collection of available content types from the site and from any of the parent sites. Properties Used: SP.Web.availableContentTypes property (sp.js)

How to retrieve the collection of content types from the SharePoint sub site? There is a property available in SP.Web (SP.js) object to retrieve the collection of content types from parent site and the current site.

The below link redirects you to the property, which helps in retrieving the collection of available content types,
https://msdn.microsoft.com/en-us/library/office/jj245696.aspx
Property Name: SP.Web.availableContentTypes property (sp.js)
The below code supports the SharePoint Online and SharePoint 2013 plus
The code returns the Content type name and its id.

Shantha Kumar
Shantha Kumar
Articles: 280

24,849 Comments

  1. Thank you so much for this! I was stuggling with a sub-site trying to retrieve the content types and it was not pulling back the parent site content types. I was using get_contentTypes() rather than get_availableContentTypes().

    So in summary:
    get_contentTypes() – Only retrieves that sites content types
    get_availableContentTypes() – Retrieves current and parent sites’ content types

Comments are closed.