Forum Discussion

llambert1110's avatar
llambert1110
Copper Contributor
Aug 05, 2022
Solved

Standard Folder Structure for Organization Template Schema

I would like to create an organization template for hub users, that automatically adds a default folder structure with subfolders. I started by creating a sample site and retrieved its schema. Now I believe I need to trigger a flow in that schema to create the folder structure based on the folder path in my sample document library. I was able to get the flow to run manually when I knew the destination but the catch is, I don't know the destination yet because I want this to run when users select our site template.  What should my power app be like? or am I going about that all wrong?

  • llambert1110 

     

    By default Get-SPOSiteScriptFromWeb command will not include folder structure from document library. 

    For that you need to update Site Design / Script JSON before adding it as Organization Template. There you can provision folder using list sub action called "addFolder". 


    Official JSON Schema for supported action: https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json 

     

    I have created sample JSON schema to provision folder inside document library:

     

    {
        "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
        "actions": [
            {
                "verb": "createSPList",
                "listName": "MyDocuments",
                "templateType": 101,
                "subactions": [
                    {
                        "verb": "setDescription",
                        "description": "List of Customers and Orders"                
                    },
                    {
                        "verb": "addFolder",
                        "path": "Folder1"
                    },
                    {
                        "verb": "addFolder",
                        "path": "Folder2"
                    },
                    {
                        "verb": "addFolder",
                        "path": "Folder1/Folder11"
                    }
                    
                ]
            }
    
        ],
        "version": 2
    }

     

    Hope it will help to you and if it does then request you to mark this as answer or like it. 

     

  • llambert1110 

     

    By default Get-SPOSiteScriptFromWeb command will not include folder structure from document library. 

    For that you need to update Site Design / Script JSON before adding it as Organization Template. There you can provision folder using list sub action called "addFolder". 


    Official JSON Schema for supported action: https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json 

     

    I have created sample JSON schema to provision folder inside document library:

     

    {
        "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
        "actions": [
            {
                "verb": "createSPList",
                "listName": "MyDocuments",
                "templateType": 101,
                "subactions": [
                    {
                        "verb": "setDescription",
                        "description": "List of Customers and Orders"                
                    },
                    {
                        "verb": "addFolder",
                        "path": "Folder1"
                    },
                    {
                        "verb": "addFolder",
                        "path": "Folder2"
                    },
                    {
                        "verb": "addFolder",
                        "path": "Folder1/Folder11"
                    }
                    
                ]
            }
    
        ],
        "version": 2
    }

     

    Hope it will help to you and if it does then request you to mark this as answer or like it. 

     

    • llambert1110's avatar
      llambert1110
      Copper Contributor

      kalpeshvaghela Thanks for this.  I used this structure in my template but am getting errors.  Here's the first part of my template, which I ran through a json linter to make sure the json was valid.

      {
      	"$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
      	"actions": [{
      			"verb": "createSPList",
      			"listName": "XXXXXX Project Name",
      			"templateType": 101,
      			"subactions": [{
      					"verb": "setDescription",
      					"description": "Standard Project File Structure"
      				},
      				{
      					"verb": "addFolder",
      					"path": "00-RFQ & Interview Information"
      				},
      				{
      					"verb": "addFolder",
      					"path": "A-Project Administration"
      				},
      				{
      					"verb": "addFolder",
      					"path": "A-Project Administration/A1-Proposals & Contracts"
      				},
      .....

       

      Here are the errors I receive:

       

      At line:2 char:14
      +     "$schema": "https://developer.microsoft.com/json-schemas/sp/site- ...
      +              ~
      Unexpected token ':' in expression or statement.
      At line:4 char:19
      +             "verb": "createSPList",
      +                   ~
      Unexpected token ':' in expression or statement.
      At line:8 char:27
      +                     "verb": "setDescription",
      +                           ~
      Unexpected token ':' in expression or statement.
      At line:12 char:27
      +                     "verb": "addFolder",
      +                           ~
      Unexpected token ':' in expression or statement.
      At line:16 char:27
      +                     "verb": "addFolder",
      +                           ~
      Unexpected token ':' in expression or statement.
      At line:20 char:27
      +                     "verb": "addFolder",
      ....

       Any idea why these errors could be happening?

       

      • kalpeshvaghela's avatar
        kalpeshvaghela
        Steel Contributor

        llambert1110 

         

        It seems that error is not for the part which you have shared because I tried below schema where I used same as you there it worked fine.

         

        {
            "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
            "actions": [
                {
                    "verb": "createSPList",
                    "listName": "MyDocuments3",
                    "templateType": 101,
                    "subactions": [
                        {
        					"verb": "setDescription",
        					"description": "Standard Project File Structure"
        				},
        				{
        					"verb": "addFolder",
        					"path": "00-RFQ & Interview Information"
        				},
        				{
        					"verb": "addFolder",
        					"path": "A-Project Administration"
        				},
        				{
        					"verb": "addFolder",
        					"path": "A-Project Administration/A1-Proposals & Contracts"
        				}
                        
                    ]
                }
        
            ],
            "version": 2
        }

         

        Is is possible for you to share other part of your template? 

  • Bharath Arja's avatar
    Bharath Arja
    Iron Contributor

    llambert1110 You can try using Site templates. Site templates can be used each time a new site is created to apply a consistent set of actions. Site templates created using custom site scripts will display in the From your organization tab in the site template gallery. 

    Check this to get started on site templates - https://support.microsoft.com/en-us/office/apply-and-customize-sharepoint-site-templates-39382463-0e45-4d1b-be27-0e96aeec8398?ui=en-US&rs=en-US&ad=US 

    • llambert1110's avatar
      llambert1110
      Copper Contributor
      I already have an understanding of the "From you Organization" templates and that is exactly what I'm attempting to create. I've already gone through the steps described but when you run the "Get Script" I listed below, it doesn't give you the folder and subfolder structure in the schema.
      I want to have a folder structure created in the document library when someone chooses this template from our organization template gallery.

      Get-SPOSiteScriptFromWeb `
      -WebUrl https://xxxxxxxx.sharepoint.com/sites/XXXXXXProjectName `
      -IncludeBranding `
      -IncludeTheme `
      -IncludeRegionalSettings `
      -IncludeSiteExternalSharingCapability `
      -IncludeLinksToExportedItems `
      -IncludedLists ("Shared Documents")
      {

Resources