Domanda

Runing this example. i have a list("announcement2") in sharepoint online account and I am able to read items from that list. When I trigger create item event below;

private listItemEntityTypeName: string = "SP.Data.announcement2ListItem";
..

private createItem(): void {
    this.getListItemEntityTypeName()
      .then((listItemEntityTypeName: string): Promise<Response> => {
        const body: string = JSON.stringify({
          '__metadata': {
            'type': listItemEntityTypeName
          },
          'Title': `Item CREATED`
        });
        return this.props.httpClient.post(`${this.siteUrl}/_api/web/lists/getbytitle('${this.props.listName}')/items`,
        SPHttpClientConfigurations.v1, {
          headers: {
            'Accept': 'application/json;odata=nometadata',
            'Content-type': 'application/json;odata=verbose',
            'odata-version': ''
          },
          body: body
        }); 
      })

I see this exception in console Response content:

{"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"A type named 'SP.Data.announcement2ListItem' could not be resolved by the model. When a model is available, each type name must resolve to a valid type."}}}

This looks about my "listItemEntityTypeName" property since I harcoded set it(if not set it its undefined). How can I solve this?

È stato utile?

Soluzione

Actually getListItemEntityTypeName should return valid entity type name. You can try to investigate why it doesn't work as expected.

If you want to provide it manually you need to be careful because entity type parameter is case sensitive. So in your case it should be SP.Data.Announcement2ListItem

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top