Summary
This is a very simple blog to create site column using Schema XML. The Schema XML can be extracted with PnP.PowerShell. First manually create the Site Column on your site. After you are happy with the created fields you can extract the information using the Save-PnPSiteTemplate. Anyhow, this post is to create the site columns in consistent way to various sites.
Step By Step
#1 Create a Manually Triggered Power Automate flow.
#2 Create Compose action, rename to something like ComposeSchemaXML. Add the following xml in the “Inputs” of compose action.
<Field Type="Text" DisplayName="Description" Description="A Sample description field." Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" Group="MyCustomFields" StaticName="reqDescription" Name="reqDescription"></Field>
#3 Call the “Send an HTTP request to SharePoint” action with the following information.
Method: POST
Uri: _api/web/fields/createfieldasxml
Headers:
{
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose"
}
Body
{
"parameters": {
"__metadata": { "type": "SP.XmlSchemaFieldCreationInformation" },
"SchemaXml": '@{outputs('ComposeSchemaXML')}'
}
}
Conclusion
This post may a simple and short post for you. It may give you a quick ways to create the multiple site columns in a consistent way.
Please make a note:
To check if the site column exists or not you can make GET call with the following uri
_api/web/fields/GetByInternalNameOrTitle(‘reqDescription ‘)
To delete the existing site column you make a POST call with above uri with headers as following.
{
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"IF-MATCH":"*",
"X-HTTP-METHOD":"DELETE"
}