3

In SharePoint 2013, I have a site column that already exists and I'm trying to associate it to an existing list using the REST API. I found examples on adding a new column to a list using the REST API but no examples on adding an existing site column. Has anyone done this before?

1

I believe this can be achieved by providing the site column's schema when creating a field in the target list.

First, the desired site column's SchemaXml property is retrieved using one of the fields endpoints:

https://[site url]/_api/web/fields('[field guid]')/SchemaXml
https://[site url]/_api/web/fields/GetByTitle('[field title'])/SchemaXml

This can then be used in the CreateFieldAsXML method to add the column to the target list:

https://[site url]/_api/web/lists/GetByTitle('[list title]')/fields/createfieldasxml

with the SchemaXml embedded in the JSON payload:

{
    "parameters": {
        "__metadata": {
            "type": "SP.XmlSchemaFieldCreationInformation"
        },
        "SchemaXml": "<Field Type=...></Field>"
    }
}

Checking the SourceID property of the newly created field confirms that it matches with that of the site column. Also, the site column is no longer listed when attempting to manually add it using the Add Columns from Site Columns page in the list's settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.