Skip to content

How to create a lookup column at site scope using site scripts ? #9481

Closed

Description

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

Site designs & site scripts

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

  • browser version
  • SPFx version
  • Node.js version
  • etc

Issue description

I need to create a list and a site column of type lookup that targets the list.

According to the documentation, site scripts can create list columns using addSPLookupFieldXml sub action, but there's no site level equivalent.

I tried to use createSiteColumnXml to specify everything manually, but I guess the List attribute is the blocking part.

According the documentation of the Field element, List attribute can be either:

  • the list ID : not possible because the list's ID cannot be controlled and will be different across sites
  • the list URL: we can infer the list url, but it's not working. The documentation state that it's working only if the list is from the same feature (which is more relevant to the good old days of provisioning web templates with elements.xml and other xml based files)

For example, this minimal site script reproduce the issue:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
  "actions": [
    {
      "verb": "createSPList",
      "listName": "MyList",
      "templateType": 100
    },
    {
      "verb": "createSiteColumnXml",
      "schemaXml": "<Field Type=\"Lookup\" DisplayName=\"MyLookup\" List=\"Lists/MyList\"  ShowField=\"Title\" Group=\"DIAG\" ID=\"{bdcdf262-a7b7-455a-8d3e-d21e4f9add63}\" StaticName=\"MyLookup\" Name=\"MyLookup\" />",
      "pushChanges": true
    }
  ]
}

The site design does not error, but in the field properties, we have no "target"

image

FYI, the actual schema xml of the column in the site is:

<Field
  Type="Lookup"
  DisplayName="MyLookup"
  List="Lists/MyList"
  ShowField="Title"
  Group="DIAG"
  ID="{bdcdf262-a7b7-455a-8d3e-d21e4f9add63}"
  StaticName="MyLookup"
  Name="MyLookup"
  SourceID="{dea7ebb7-cd95-41aa-a125-a00da36fdd56}"
  Version="1"
/>

I tried various versions of the schema, playing with Overwrite="TRUE" DisplaceOnUpgrade="TRUE" parameters as I did on old onprem features, but nothing works.

How to solve this ?

PS: I'm aware that triggering a flow can overcome the limitation, but it introduces a lot of complexity, since the invoke flow action is asynchronous, and make subsequent site script actions hard to orchestrate.

PS2: The site script could have been awesome if it evolved. It never changes since its initial release AFAIK and even if some undocumented actions are presents in the schema, these actions are not working. What are the plan regarding this sitescripts?

Activity

  1. ghost added
    Needs: Triage 🔍Awaiting categorization and initial review.
    on Jan 24, 2024
  2. added
    type:questionQuestion... if answered, will be tagged as such.
    area:site-designCategory: Site Designs/Site Scripts
    and removed
    Needs: Triage 🔍Awaiting categorization and initial review.
    on Jan 29, 2024
  3. expiscornovus commented on Jan 24, 2025

    @expiscornovus
    Contributor

    Hi Steve Beaugé (@stevebeauge),

    Edit: apologies, I did not read this thread properly. You are looking for a site column, not a list column. In that case ignore the below. 😅

    I was running into a similar issue and came across this thread.

    Not sure if it helps, since this is a year ago. But for me it worked when I used the addSPLookupFieldXml in a subactions array instead.

    Below is an example.

    {
         "$schema": "schema.json",
             "actions": [
                {
                    "verb": "createSPList",
                    "listName": "Tasks",
                    "templateType": 100,
                    "subactions": [
                        {
                            "verb": "setDescription",
                            "description": "Example Tasks List"
                        }
                    ]
                },
                {
                    "verb": "createSPList",
                    "listName": "Deliverables",
                    "templateType": 100,
                    "subactions": [
                        {
                            "verb": "addSPLookupFieldXml",
                            "schemaXml": "<Field Type=\"Lookup\" DisplayName=\"Deliverable Task\" Required=\"FALSE\" EnforceUniqueValues=\"FALSE\" ShowField=\"Title\" UnlimitedLengthInDocumentLibrary=\"FALSE\" RelationshipDeleteBehavior=\"None\" ID=\"{101f1f89-d667-4c7f-9ebc-76cb5831d0a2}\" StaticName=\"DeliverableTask\" Name=\"DeliverableTask\" />",
                            "targetListName": "Tasks"
                        }
                    ]
                }
    ],
    "bindata": { },
    "version": 1
    }
    
  4. stevebeauge commented on Jan 24, 2025

    @stevebeauge
    Author

    Don't worry 😂

    I came to the conclusion that site design is a half finished feature. Lot of things are not properly handled or inexistant 😕

  5. Ashlesha-MSFT commented on Jul 17, 2025

    @Ashlesha-MSFT
    Contributor

    Hi Steve Beaugé (@stevebeauge),
    I'm following up on the issue.

    As there hasn't been recent activity on the thread recently, I wanted to check if you've been able to find a workaround or if the issue has been resolved in any recent updates to SharePoint Online or site script capabilities.

  6. stevebeauge commented on Jul 17, 2025

    @stevebeauge
    Author

    Hi Ashlesha-MSFT

    Unfortunately no. Site scripts are still very limited, didn't evolved after the initial release and creating a site column is still not possible (alongside a lot of missing features, out of the scope of this issue).

  7. Ashlesha-MSFT commented on Jul 18, 2025

    @Ashlesha-MSFT
    Contributor

    Steve Beaugé (@stevebeauge),
    Thank you for the confirmation and for clearly outlining the limitation.

    Based on your description, this appears to be a feature request — specifically, the ability to create a lookup-type site column via site scripts, which is currently unsupported.

    I'll go ahead and raise this feature request on my end for consideration in future updates to site script capabilities.

  8. VesaJuvonen commented on Nov 3, 2026

    @VesaJuvonen
    Contributor

    This issue is more than 12 months old and has not had recent activity. We are cleaning up the backlog so we can manage incoming reports more efficiently. If the issue is still relevant, please submit a new issue with updated details and current reproduction steps. We apologize for any inconvenience caused by this updated process, and thank you for being part of the SharePoint developer ecosystem.

  9. github-actions commented on Nov 3, 2026

    @github-actions

    Thank you for taking the time to file an issue. We periodically archive older or inactive issues as part of our issue management process, which automatically closes them once they are archived.

    If you’d like to understand more about why and how we handle archived (closed) issues, please see Our approach to closed issues.

    We appreciate your contribution and if this is still an active issue with the latest SPFx versions, please do resubmit the details. We needed to perform a cleanup, so that we can start with a clean table with a new process. We apologize for the inconvenience this might cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:site-designCategory: Site Designs/Site Scriptssharepoint-developer-supportsharepoint-developer-supporttype:archive-old-issueIssues which are closed as tool old for active worktype:questionQuestion... if answered, will be tagged as such.type:uservoice-requestEnhancements & feature requests should be posted: http://aka.ms/sp-dev-uservoice

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions