Introduction
In this article, we will learn how to create a lookup field in an existing SharePoint list using REST API and schema XML. The REST API enables us to communicate with SharePoint using standard HTTP methods, such as GET, POST, PUT, and DELETE. The API provides access to various SharePoint entities including lists, libraries, and sites, allowing us to retrieve data, create and update lists, fields, items, upload files and manage user permissions.
Prerequisites
- Access to a SharePoint site with permissions to create lists and fields
Below are the steps,
Step 1. Create a lookup list
The first step is to create the list that you want to be the source of the lookup field. I will use the "Department" list with the "Title" column as a source for creating the lookup field in this demo.
Step 2. Create a new list
Create a new list and use it to create a multiselect lookup field by using the lookup list created in the previous step as its source.
Step 3. Create REST API request body
For creating the multiselect lookup field using the REST API, we need to define the request body for the API call. This body will contain the schema XML for the field, which must include the following properties:
Step 4. Make the REST API Call
With the request body defined, you are now ready to make the REST API call. You can use any REST client to make the call, such as Postman. The REST API call should be made to the following URL:
_api/web/lists/getbytitle('[source-list-name]')/fields/CreateFieldAsXml
The request should be a POST request and the request body should contain the schema XML defined in the previous step.
Output
After making the REST API call, you can verify that the multiselect lookup field was created by going to the destination list's settings page and checking the list of fields.
List view
Conclusion
In this article, we have learned to create multiselect lookup field using REST API and schema XML. Thank you for reading.