Sharepoint - Creating Lookup column using rest which can take multiple values
You can create lookup column from SchemaXml
. For multi value lookup column, SchemaXml
looks like
var lookupShema = "<Field Type=\"LookupMulti\" DisplayName=\"MultipleLookup\" Required=\"FALSE\" EnforceUniqueValues=\"FALSE\" List=\"{92a6545e-e509-430b-a6a6-16bdb7a81b33}\" ShowField=\"ID\" Mult=\"TRUE\" Sortable=\"FALSE\" UnlimitedLengthInDocumentLibrary=\"FALSE\" RelationshipDeleteBehavior=\"None\" ID=\"{32e8961d-d69f-448e-bf9a-f2246185d389}\" SourceID=\"{233ae45e-f581-4420-b069-b7a74d368b13}\" StaticName=\"MultipleLookup\" Name=\"MultipleLookup\" ColName=\"int3\" RowOrdinal=\"0\" Version=\"1\" /> "
See MSDN example for more details.
$.ajax({
url: "http://<site url>/_api/web/lists(guid'da58632f-faf0-4a78-8219-99c307747741')
/fields",
type: "POST",
data: { '__metadata': { 'type': 'SP.Field' }, 'FieldTypeKind': 20, 'Title':
'Stakeholders', 'SchemaXml': '<Field Type=\"UserMulti\" Required=\"TRUE\"
UserSelectionMode=\"PeopleAndGroups\" UserSelectionScope=\"0\" Mult=\"TRUE\" />' },
headers: {
"X-RequestDigest": <form digest value>,
"accept": "application/json; odata=verbose",
"content-type": "application/json;odata=verbose",
"content-length": <length of body data>
},
success: successHandler,
error: errorHandler
});
Add parameter 'AllowMultipleValues': true
Edit
To change lookup and enable allow multiple values You can refer same MSDN which Atish shared :
$.ajax({
url: "http://<site url>/_api/web/lists(guid'da58632f-faf0-4a78-8219-99c307747741')
/fields('1d22ea11-1e32-424e-89ab-9fedbadb6ce1')",
type: "POST",
data: "{ '__metadata': { 'type': 'SP.FieldLookup' }, 'AllowMultipleValues': true }",
headers: {
"X-RequestDigest": <form digest value>,
"content-type": "application/json;odata=verbose",
"content-length": <length of body data>,
"X-HTTP-Method": "MERGE"
},
success: successHandler,
error: errorHandler
});