2

I am trying to create a lookup column using the SharePoint REST API but can't figure out a way to pull the additional columns from the source list.

I am using SP.FieldCreationInformation to do this. Code sample below. Is there any way to pull the additional columns from the source list and create them at the same time? Basically, I want to know if the REST API will allow me to use the "Select additional columns" functionality that you can utilize in the GUI? (Image below)

enter image description here

"headers": {
            "X-RequestDigest": "form digest value",
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "content-length": "length of body data"
        },
        "body": "{ 'parameters': { '__metadata': { 'type': 'SP.FieldCreationInformation' }, 'FieldTypeKind': 7,\n    'Title': 'User', 'LookupListId': '53ca895d-8f0c-40ae-ab7a-01d1b7a6dc0e',\n    'LookupFieldName': 'Title' } }"

1 Answer 1

0

After creation of your lookup field you can call another rest api as shown below to add the dependent (additional) fields.

$.ajax({
    url: "http://<site url>/_api/web/lists(guid'da58632f-faf0-4a78-8219-99c307747741')/fields/adddependentlookupfield(displayname='Project', primarylookupfieldid='c3a92d97-2b77-4a25-9698-3ab54874bc6f', showfield='Title')",
    type: "POST",
    headers: {
        "X-RequestDigest": <form digest value>>,
        "accept": "application/json;odata=verbose"
    },
    success: successHandler,
    error: errorHandler
});

Check this article if you need more help. Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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