SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

To create a lookup column..

$.ajax({
  url: "https://test/_api/Lists/getbytitle('abc')/fields/addfield",
  type: "POST",
  data: "{ 'parameters': { '__metadata': { 'type': 'SP.FieldCreationInformation' }, 'FieldTypeKind': 7,'Title': 'Platform', 'LookupListId': '30dfdfd3-013A-4D31-8E84-s542434332432','LookupFieldName': 'Platform_x0020_Name' } }",
  headers: { 
    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
    "accept": "application/json;odata=verbose",
    "content-type": "application/json;odata=verbose",

  },
  success: function(d) {
        alert("added");
                },
  error:  function(e) {
                alert("error"); 
        }
});

this creates a lookup column but I need this column to take multiple values.

enter image description here

allow multiple value checkbox should be checked.

share|improve this question
    
Can you try Mult:"TRUE" in request body? Meaning use data: "{ 'parameters': { '__metadata': { 'type': 'SP.FieldCreationInformation' }, 'FieldTypeKind': 7,'Title': 'Platform', 'LookupListId': '309AC643-013A-4D31-8E84-3382248FF202','LookupFieldName': 'Platform_x0020_Name' , 'Mult': true} }" – Atish Dipongkor Jan 5 at 11:36
    
Error is coming The property 'Mult' does not exist on type 'SP.FieldCreationInformation' – vikash kumar Jan 5 at 11:40
up vote 2 down vote accepted

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
});
share|improve this answer
    
Nope .... It does not work! – Atish Dipongkor Jan 5 at 11:47
    
Ohh Ok , it should I guess. Have you tried. – Bhaskar Dhone Jan 5 at 11:49
    
Yup..... error is The property 'AllowMultipleValues' does not exist on type 'SP.FieldCreationInformation'. Make sure to only use property names that are defined by the type. – Atish Dipongkor Jan 5 at 11:50
    
You are right. That is for SP.FieldLookup – Bhaskar Dhone Jan 5 at 11:53

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
});
share|improve this answer
$.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
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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