How to get ContentType Data in sharepoint using sharepoint framework and access data properties using spfx react js pnp

Payal Agrawal 0 Reputation points
2023-05-11T11:30:33.3966667+00:00
public async compoundDidMount(){

let contentData = await sp.web.contentTypes.get();

contentData.foreach(data => {

this.listData.push({ key : data.Name, text : data.Name});

});

}

this listdata I am using in my dropdown to bind data. After this code I was expecting content type data but it's showing parent data.

Where I am wrong? could anyone help me please? Also I need to fetch all the properties of data

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,822 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,008 questions
.NET F#
.NET F#
.NET: Microsoft Technologies based on the .NET software framework.F#: A strongly typed, multi-paradigm programming language developed by the F# Software Foundation, Microsoft, and open contributors.
105 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 36,171 Reputation points Microsoft Vendor
    2023-05-17T06:40:05.3333333+00:00

    Hi @Payal Agrawal

    Per my test, you could use following code to retrieve ContentType data

    private getContentTypeData(): void {
      sp.web.contentTypes
        .select("Id", "Name", "Description")
        .get()
        .then((contentTypes) => {
          console.log(contentTypes); // You can perform further operations with the contentTypes data
        })
        .catch((error) => {
          console.log(`Error: ${error}`);
        });
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.