10

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.

  • 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 - MVP Jan 5 '16 at 11:36
  • Error is coming The property 'Mult' does not exist on type 'SP.FieldCreationInformation' – KumarV Jan 5 '16 at 11:40
2

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
});
  • Nope .... It does not work! – Atish Dipongkor - MVP Jan 5 '16 at 11:47
  • Ohh Ok , it should I guess. Have you tried. – Bhaskar Dhone Jan 5 '16 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 - MVP Jan 5 '16 at 11:50
  • You are right. That is for SP.FieldLookup – Bhaskar Dhone Jan 5 '16 at 11:53
3

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
});
1
$.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
});

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.