I am working on sharepoint on-premises 2013. and i have a cusotm list which contain 2 columns of type "Choice", as follow:--
Now i am trying to copy one list item and create a new list item, using SharePoint REST API. Currently i am able to populate all the values, but when it comes to the above 2 columns of type choice i received the following error, if the item have the choice unchecked:-
An unexpected 'PrimitiveValue' node was found when reading from the JSON reader. A 'StartObject' node was expected.
while if the list item has the checkboxes checked everything will work well. here is part of my API call, where the 2 columns named as "QuickOrder" & "SOFRequired" are being passed to the list api:-
var QuickOrder= "";
var SOFRequired="";
$.ajax({
url: "*****_api/web/lists/getbytitle('Order Management')/items?$filter=(Id eq "+ orderID+")",
method: "GET",
async: false,
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
if(data.d.results.length>0){
var items=data.d.results;
for(var i=0;i<items.length;i++){
if(items[i].QuickOrder != null && items[i].QuickOrder != "undefined")
{
QuickOrder = items[i].QuickOrder;
}
if(items[i].SOFRequired != null && items[i].SOFRequired != "undefined")
{
SOFRequired = items[i].SOFRequired;
}
//inializet the json object
var item = {
"__metadata": { "type": itemType },
"Title": title2 ,
"QuickOrder":QuickOrder,
"SOFRequired":SOFRequired
};
//call to create new item
$.ajax({
url: "/*****/_api/web/lists/getbytitle('Order Management')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
Now i think the problem is that sharepoint store the Choice value as an object and not as a direct string value (for example Yes). here is a json response, observed from my F12 tool, for my QuickOrder field, and if the checkbox is not check the value will be = null:-
So can anyone advice how i can fix the error i am getting when passing empty values for my Choice fields?