SharePoint / SharePoint/sp-dev-docs

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

Open
#9,481 6 comments 0 reactions 1 assignee View on GitHub

@Ashlesha-MSFT is already working on this.

Since Jul 16, 2025.

area:site-design sharepoint-developer-support type:question type:uservoice-request
Dominant language
PowerShell
Stars
1.4k
Forks
1.1k
Avg merge
4d 12h
Merged PRs (30d)
12

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.