1

I want to create list item using listdata.svc in SharePoint Online. I'm using following code to save item into the list.

item = {
        "YearQtr"                       : $("#lblQuarter").text(),
        "StatusValue"                   : status,
        "Title"                         : $("#lblEmpName").text(),
        "EmployeeNameId"                : _spPageContextInfo.userId,
        "EmployeeId"                    : $("#lblEmpId").text(),
        "Department"                    : $("#lblEmpDepartment").text(),
        "Designation"                   : $("#lblEmpDesignation").text(),
        "HireDate"                      : $("#lblEmpHireDate").text(),
        "PrimaryManagerId"              : $("#hdnEmpPrimaryManagerId").text(),
        "SecondaryManagerId"            : $("#hdnEmpSecondaryManagerId").text() == "" ? 0 : $("#hdnEmpSecondaryManagerId").text(),
        "ProjectNameId"                 : $("#ddlProjectName").val(),
        "ProjectRoleId"                 : { "results" : projectRole},
        "Path"                          : _spPageContextInfo.webServerRelativeUrl + "/Lists/" + targetListInternalName + "/" + _spPageContextInfo.userLoginName
    };

    $.ajax({
        async: false,
        url: _spPageContextInfo.webAbsoluteUrl + "/_vti_bin/listdata.svc/" + targetListInternalName,
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function(data){

            if(data.d != undefined && data.d != null){
                if(isSubmit){
                    SendEmailNotification(data.d.Id);
                }
                CloseForm();
            }
        },
        error: function(error){
            ShowErrorMessage(error);
        }
    });

I'm supplying projectRole value as array of Lookup ID.

In above example ProjectNameId is single lookup & ProjectRoleId is multi lookup field. While I tried to save item using this code, it's giving me an error.

If I make Project Role field as single lookup and save data as similar to ProjectName field then it allows me to save the record.

Any help will be appreciated.

Looking forward to hear from you.

-1

Try with below code.

var data = JSON.stringify({
    MultiLookupColumnName:[
        { 
            __metadata: { 
                uri: "http://yoursiteurl/_vti_bin/ListData.svc/LookupListName(1)"
            }
        },
         { 
            __metadata: { 
                uri: "http://yoursiteurl/_vti_bin/ListData.svc/LookupListName(2)"
            }
        }
    ]
});

Reference Link : SP2010 Add/Update multi-select lookup column REST

|improve this answer|||||
  • I tried this one also, however it's not working in my case as number of lookup value is dynamic – Jay Doshi Feb 16 '17 at 16:30

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.