Updating base content type - Violation?

Brass Contributor

Hi,

 

I have a Site Script where I add Site Columns to the Site Pages library. My issue is when adding site columns via site script then the Repost Page content type is not inheriting the added columns, only the Site Page content type. Adding a column via the UI works as there is an option "Add to all content types" which is missing in site script.

 

Below Site Script fails to have both the Site Page and Repost Page to inhering the added column:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
  "actions": [            
    {
      "verb": "createSPList",
      "listName": "Site Pages",
      "templateType": 119,
      "subactions": [
        {
          "verb": "addSiteColumn",
          "internalName": "PageCategory",
          "addToDefaultView": true
        },
        ....
      }
    ]
}

 

Something that works though is to add the columns to the base site content types however is this "OK" or is this approach violating recommended practices/rules?

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
  "actions": [
    {
      "verb": "createContentType",
      "name": "Site Page",
      "description": "Create a new site page",
      "hidden": false,
      "parentName": "Document",
      "subactions":
        [
            {
              "verb": "addSiteColumn",
              "internalName": "PageCategory"
            }           
        ]
    },
    {
      "verb": "createContentType",
      "name": "Repost Page",
      "description": "Used to create a News link post. If deleted, the News link option will be disabled for users.",
      "hidden": false,
      "parentName": "Site Page",
      "subactions":
        [
          {
            "verb": "addSiteColumn",
            "internalName": "PageCategory"
          }
        ]
    },        
    {
      "verb": "createSPList",
      "listName": "Site Pages",
      "templateType": 119,
      "subactions": [
        {
          "verb": "addContentType",
          "name": "Site Page"          
        },
        {
          "verb": "addContentType",
          "name": "Repost Page"
        }
        ...
      ]
   }
}

 

NOTE: Know that PnP can be used however would like to use Site Design/Site Script and would also like to skip creation of own content types.

1 Reply

@Adam Andersson In my opinion, one should be careful of manipulating a base site content type, because changes you make on it affects all content types inheriting from it (OOTB behaviour). I believe that the best approach is to create a new custom content type which inherits from the base content type. Then add your new site column only to the custom content type.