문제

Ok I am running into issues for creating a choice field within a document library.

I cannot get the addSPLookupFieldXML to work properly within the JSON template.

Any ideas on what I am doing wrong?

Been using these links to try and figure it out:

https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-json-schema

https://docs.microsoft.com/en-us/sharepoint/dev/schema/field-element-field

{
    "verb": "createSPList",
    "listName": "Test List",
    "templateType": 101,
    "subactions": [
      {
        "verb": "setDescription",
        "description": "Teat List Library"
      },
      {
        "verb": "addSPLookupFieldXml",
        "schemaXml": "Field Type"\"Choice"
        "isRequired": false,
        "addToDefaultView": true
      }   
    ]
  },
도움이 되었습니까?

해결책

If you are trying to add a choice column to your list then you need to pass the choices to field. Check below example:

{
  "verb": "addSPFieldXml",
  "schemaXml": "<Field ID=\"{596cbd92-36e3-40cc-a910-0f53468ce5e4}\" Type=\"Choice\" DisplayName=\"Project Category\" Required=\"FALSE\" Format=\"Dropdown\" StaticName=\"ProjectCategory\" Name=\"ProjectCategory\"><Default>Operations</Default><CHOICES><CHOICE>Operations</CHOICE><CHOICE>IT</CHOICE><CHOICE>Legal</CHOICE><CHOICE>Engineering</CHOICE></CHOICES></Field>"
}

Documentation: Site design JSON schema - addSPFieldXml

Update from Comments:

If you are using it across multiple site collections and multiple document libraries then I will recommend you to create this choice field as Site Column. Below is the example code the creating a site column, adding to a content type and adding it to document library:

{
    "$schema": "schema.json",
    "actions": [
        {
            "verb": "createSiteColumn",
            "fieldType": "User",
            "internalName": "PolicyOwner",
            "displayName": "Policy Owner",
            "isRequired": false,
            "group": "DevFacto IS Custom Columns",
            "enforceUnique": false
        },
        {
            "verb": "createSiteColumnXml",
            "schemaXml": "<Field Type=\"Choice\" DisplayName=\"Policy Type\" Required=\"FALSE\" Format=\"Dropdown\" StaticName=\"PolicyType\" Name=\"PolicyType\"><Default></Default><CHOICES><CHOICE>Policy</CHOICE><CHOICE>Procedure</CHOICE></CHOICES></Field>"
        },
        {
            "verb": "createSiteColumn",
            "fieldType": "DateTime",
            "internalName": "PolicyExpiryDate",
            "displayName": "Policy Expiry Date",
            "isRequired": false,
            "group": "DevFacto IS Custom Columns"
        },
        {
            "verb": "createContentType",
            "name": "Policy",
            "description": "Policy Document",
            "parentName": "Document",
            "hidden": false,
            "subactions": [
                {
                    "verb": "addSiteColumn",
                    "internalName": "PolicyOwner"
                },
                {
                    "verb": "addSiteColumn",
                    "internalName": "PolicyType"
                },
                {
                    "verb": "addSiteColumn",
                    "internalName": "PolicyExpiryDate"
                }
            ]
        },
        {
            "verb": "createSPList",
            "listName": "Documents",
            "templateType": 101,
            "subactions": [
                {
                    "verb": "addContentType",
                    "name": "Policy"
                },
                {
                    "verb": "addSPView",
                    "name": "By Policies",
                    "viewFields": [
                        "Name",
                        "PolicyOwner",
                        "PolicyType",
                        "PolicyExpiryDate",
                        "Modified",
                        "Editor",
                        "Version"
                    ],
                    "query": "<OrderBy><FieldRef Name=\"Name\" Ascending=\"FALSE\" /></OrderBy><GroupBy Collapse =\"TRUE\"><FieldRef Name =\"PolicyType\"/></GroupBy><Where><Eq><FieldRef Name=\"ContentType\"/><Value Type=\"Computed\">Policy</Value></Eq></Where>",
                    "rowLimit": 100,
                    "isPaged": true,
                    "makeDefault": false
                }
            ]
        }
    ],
    "bindata": {},
    "version": 1
}

You can read more about it at:

  1. Getting Started with SharePoint Site Designs and Site Scripts

다른 팁

You could try this:

$site_script = '
    {
        "$schema": "schema.json",
            "actions": [
                {
                    "verb": "createSPList",
                    "listName": "testLib",
                    "templateType": 101,
                    "subactions": [
                        {
                            "verb": "setDescription",
                            "description": "testlib"
                        },
                        {
                            "verb": "addSPField",
                            "fieldType": "Text",
                            "displayName": "Name",
                            "isRequired": false,
                            "addToDefaultView": true
                        },
                {
  "verb": "addSPFieldXml",
  "schemaXml": "<Field ID=\"{596cbd92-36e3-40cc-a910-0f53468ce5e4}\" Type=\"Choice\" DisplayName=\"Project Category\" Required=\"FALSE\" Format=\"Dropdown\" StaticName=\"ProjectCategory\" Name=\"ProjectCategory\"><Default>Operations</Default><CHOICES><CHOICE>Operations</CHOICE><CHOICE>IT</CHOICE><CHOICE>Legal</CHOICE><CHOICE>Engineering</CHOICE></CHOICES></Field>"
},                  
                    ]
                }
            ],
                "bindata": { },
        "version": 1
    } '

Test result: enter image description here enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top