I'm trying to update a SharePoint List with the name "Director's Task List (DTL)" for single items in it. I've got the following code:
var listName = 'Director''s Task List (DTL)';
var requestURI = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items(" + ID + ")";
$.ajax({
uri: requestURI,
type: "POST",
contentType: "application/json; odata=verbose",
data: JSON.stringify(data),
headers: {
"Accept": "application/json; odata=verbose",
"X-HTTP-Method": "MERGE",
"IF-MATCH": "*",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
}
});
where data is:
var data = {
'__metadata': { 'type': getItemTypeForListName(listName)},
'Suspense_x0020_Status' :
{
'__metadata': { 'type': 'SP.FieldUrlValue' },
'Description': statusObject[ID]["color"],
'Url': statusObject[ID]["html"]
}
};
and getItemTypeForListName(listName) is:
function getItemTypeForListName(listName) {
var itemType = "SP.Data." + listName.charAt(0).toUpperCase() + listName.slice(1) + "ListName";
var encItemType = itemType.replace(/\s/g,'_x0020_');
return(encItemType);
}
I am unable to get the code to complete correctly. I get an error:
A type named 'SP.Data.Director''s_x0020_Task_x0020_List_x0020_(DTL)ListName' could not be resolved by the model. When a model is available, each type must resolve to a valid type.
I know it has something to so with spaces and the single apostrophe, but I have tried several solutions, without luck. I have seen that the double single apostrophe, "''" , is a working method that has helped for me before in getting this list name type to work. So don't instantly point to that.
Any thoughts?
It seems
getItemTypeForListNamefunction returns wrong list item entity type name.The following endpoint returns the actual list item entity type name:
/_api/web/lists/GetByTitle('<list title>')?$select=ListItemEntityTypeFullNameFor the list title:
Director's Task List (DTL):SP.Data.Director''s_x0020_Task_x0020_List_x0020_(DTL)ListNameSP.Data.Directors_x0020_Task_x0020_List_x0020_DTLListItemExample
The example shows how to return list item type name:
where