question

ghostmaster-8831 avatar image
0 Votes"
ghostmaster-8831 asked ghostmaster-8831 commented

Sharepoint rest api create field and add to all content type

Hi,

i am able to create a new field in a sharepoint list using the "createfieldasxml" method of "fields" endpoint.
There is a way to add this field to all content type, and not just to the default content type?
The other way i thought is to add manually every field i need to all the content type, but it's not the best solution.

Thanks




office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MichaelHan-MSFT avatar image
1 Vote"
MichaelHan-MSFT answered ghostmaster-8831 commented

Hi @ghostmaster-8831,

You could set the Options property to 4(AddToAllContentTypes) in the body using createfieldasxml method like the below:


 {
   "parameters": {
     "__metadata": {
       "type": "SP.XmlSchemaFieldCreationInformation"
     },
     "SchemaXml": "<Field Type='Text' DisplayName='test' Name='test'></Field>",
     "Options":4
   }
 } 

The AddFieldOptions value can be found here: https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-csom/ee542202(v=office.15)


If an Answer is helpful, please click "Accept Answer" and upvote it.
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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes, it works! Thank you

0 Votes 0 ·