1

I am trying to update a field in my list but I keep getting this error:

"A type named 'SP.Data.ttcuAnnListItem' could not be resolved by the model. When a model is available, each type name must resolve to a valid type"

This is the code:

    function UpdateListItem(listName,itemId,titleVal){
    var itemType = GetItemTypeForListName(listName);
    var item = {
        "__metadata": { "type": itemType },
        "Title": titleVal    
    };

    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items("+itemId+")",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "X-HTTP-Method": "MERGE",
            "If-Match": "*"
        },
        success: function (data) {
            alert('Success');
        },
        error: function (data) {
            alert("Error");
        $("#title1").html(JSON.stringify(data));
        }
    });
}

And the code for the GetItemTypeForListName function :-

// Get List Item Type metadata
function GetItemTypeForListName(name) {
    return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}
2

Hello if you only want ListItemEntityTypeFullName once the you get the name from browser by browsing with below endpoint

your siteurl/_api/web/lists/getByTitle('ttcuAnn')?$select=ListItemEntityTypeFullName

or if you want to get in code below is the script

function getItemTypeList(listName){
return jQuery.ajax({
    method: 'GET',
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('" + listName + "')?$select=ListItemEntityTypeFullName",
    contentType: "application/json;odata=verbose",
    headers: {
                "Content-Type": "application/json;odata=verbose",
                'Accept': "application/json;odata=verbose",
            },
    data: JSON.stringify(""),
});
}    

function UpdateListItem(listName,itemId,titleVal,itemTypeList){
//var itemType = GetItemTypeForListName(listName);
var item = {
    "__metadata": { "type": itemTypeList},
    "Title": titleVal    
};

$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items("+itemId+")",
    type: "POST",
    contentType: "application/json;odata=verbose",
    data: JSON.stringify(item),
    headers: {
        "Accept": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
        "X-HTTP-Method": "MERGE",
        "If-Match": "*"
    },
    success: function (data) {
        alert('Success');
    },
    error: function (data) {
        alert("Error");
    $("#title1").html(JSON.stringify(data));
    }
});
}

getItemTypeList('ttcuAnn').then(function(data){UpdateListItem(listName,itemId,titleVal,data.d.ListItemEntityTypeFullName);},function(data){alert(''call failed!)})
0

You need to confirm that the Metadata Type is in fact SP.Data.ttcuAnnListItem.

You can do this easily by performing a Rest API GET request on the \items endpoint. In the response you will see the correct type name. What you POST will need to match this. You can check this directly in the browser for a specific list using this url format https://<sitename>/_api/web/lists/getbytitle(<**ListName**>)/items

Or, If you wish to leave the function generic, you could update your GetItemTypeForListName function to actually perform the GET request in order to parse it and return the correct type name.

  • Thank you for answering, I am new to Rest can you please tell me how to check this directly in the browser? – Raghad Bogery Aug 8 '18 at 8:11
  • Please see my updated answer, and please upvote or mark as answer if it is helpful for you. – James Randal Aug 8 '18 at 8:16
  • The url doesn't redirect me to the list, I also tried this method before posting but it is also not working: function getItemTypeForListName(listTitle) { return executeJson({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/?$select=ListItemEntityTypeFullName", method: 'GET' }).then(function(data){ return data.d.ListItemEntityTypeFullName; }); } – Raghad Bogery Aug 8 '18 at 8:29
  • Also what is surprising is that I am using the same function to read items from the list and it's working fine, just when I update them I get the error – Raghad Bogery Aug 8 '18 at 8:37

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.