I have a list name "Parts", This list has a lookupfield called Parts and it look into the Parts list.
Aka 1 part can contain other parts. Hope you get the Idea
When I'm trying to update the LookUpField with either a single value or multiple values, I get an error.
An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected.
I have tried the following:
var customerData = {
__metadata: { 'type': 'SP.Data.'+Type+'ListItem' },
Title: Title,
Image: {Description:'',Url: Image},
Parts: 7
};
var customerData = {
__metadata: { 'type': 'SP.Data.'+Type+'ListItem' },
Title: Title,
Image: {Description:'',Url: Image},
PartsId: 7
};
var customerData = {
__metadata: { 'type': 'SP.Data.'+Type+'ListItem' },
Title: Title,
Image: {Description:'',Url: Image},
PartsId: {'results': 7}
};
var customerData = {
__metadata: { 'type': 'SP.Data.'+Type+'ListItem' },
Title: Title,
Image: {Description:'',Url: Image},
PartsId: {'results': [7] }
};
I keep getting the same Error no matter what I try. I've made sure that i have an item with id 7;
Here is the complete code:
var requestUri = _spPageContextInfo.webAbsoluteUrl + '/_api/Web/Lists/getByTitle(\''+Type+'\')/items('+id+')';
var requestHeaders = {
'Accept': 'application/json;odata=verbose',
'X-RequestDigest': $('#__REQUESTDIGEST').val(),
'X-HTTP-Method': 'MERGE',
'If-Match': '*'
};
var customerData = {
__metadata: { 'type': 'SP.Data.'+Type+'ListItem' },
Title: Title,
Image: {Description:'',Url: Image},
PartsId: 7
};
requestBody = JSON.stringify(customerData);
$.ajax({ url: requestUri, type: 'POST',
contentType: 'application/json;odata=verbose', headers: requestHeaders,
data: JSON.stringify(customerData)
,
success: function (response)
{
$(".check").attr("class", "check check-complete success");
$(".fill").attr("class", "fill fill-complete success");
$(".path").attr("class", "path path-complete");
setTimeout(
function()
{
closeDialog();
}, 2000);
},
error: function(error)
{
console.log(error)
}
});
If i only use Title and Image then it works just fine.