Conditions: SP 2010, html/javascript, using REST to read/write to various lists. Im using a jquery multiselect plugin to set a multi-value lookup column. I need the selecting Groups of items, easy filtering, etc. features. http://www.erichynds.com/blog/jquery-ui-multiselect-widget
On this form, one of the columns I need to update is a multi-value lookup column. I have successfully built the array it wants with the __metadata object, like so:
{ __metadata: { uri: myURI + myLookupId + ")" } }
This works great to send new lookup values to the column, but SharePoint does not replace the lookup values with the array of values I am sending it, it only adds new ones.
Is there a way to bulk remove the values in the lookup column? Wipe it clean? So I can have it be empty before I send it my array of lookup values?
I found how to delete the lookup values one by one, but have had no success finding a way to clear all the values.
http://yetanothersharepointblog.wordpress.com/2013/03/29/updating-sharepoint-multi-value-lookup-fields-using-the-rest-api/
If possible I would like to avoid writing a helper function that tracks every time a user checks or un-checks a box, then compares that to the columns lookup values, etc.
If there is a way to do clear the lookup column via the sharepoint object model instead of REST, I'm ok with that too.
Thanks for any help!
Here is the ajax call in case it will help. Maybe there is a special way of sending it so it replaces the data?
// user clicks submit, fires this function
// The url and columns (mybody) are stored and sent to the function
function UpdateMtgItem(url, mybody) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
processData: false,
beforeSend: beforeSendFunction,
url: url,
data: mybody,
dataType: "json",
success: function (data) { alert("Saved."); },
error: function () { alert("error"); }
}); beforeSendFunction = function (xhr) {
xhr.setRequestHeader("If-Match", "*");
// Using MERGE so that the entire entity doesn't need to be sent over the wire.
xhr.setRequestHeader("X-HTTP-Method", 'MERGE');
}
}