Error on Metadata type when I try to do POST

Asked

Viewed 32 times

0

I have this code:

function insertuser(obj){
        var listID = obj.getAttribute('data-listid'),
            itemID = obj.getAttribute('data-itemid'),
            URLID = obj.getAttribute('data-itemurl');

        var UserId = _spPageContextInfo.userId;

        var returl = URLID;
        var res1 = returl.substring(0,62);
        var REGEX = /.*\/Normativo\/(.+?)\/.*/;
        var res2 = returl.replace(REGEX, "$1");

        var res3 = res1.concat(res2);

        jQuery.ajax({
            url: res3 + "/_api/web/lists('" + listID + "')/items('" + itemID +"')?$select=ID,Title,QuemLeu/Id&$expand=QuemLeu",
            method: "GET",
            headers: {
                "Accept": "application/json; odata=verbose" 
            },
            success: function (data) {

                var userIdArray = [];
                if(data.d){
                    if(data.d.QuemLeu.results) {
                        for (var i = 0; i < data.d.QuemLeu.results.length; i++) {
                            userIdArray.push(data.d.QuemLeu.results[i].Id);
                        }
                    }
                }
                userIdArray.push(UserId);
                var fields = {
                    "__metadata": { 'type': "SP.Data.PaginasItem"},
                    "QuemLeuId": {"results": userIdArray  }
                }
                updateItem(fields);
            }, 
            error: function (error) {
                console.log(error);
            }
        });


        function updateItem(fields) {
            jQuery.ajax({  
                url: res3 + "/_api/web/lists('" + listID + "')/items('" + itemID +"')",  
                type: "POST",
                    data: JSON.stringify(fields),  
                    contentType: "application/json;odata=verbose",
                    headers: {  
                        "Accept": "application/json;odata=verbose",
                        "X-RequestDigest" : document.getElementById("__REQUESTDIGEST").value,
                        "X-HTTP-Method": "MERGE",
                        "If-Match": "*"  
                    },  
                success: function(data) {  
                   console.log("OK POST");
                   alert("OK POST");
                },  
                error: function(error) {  
                    console.log("ERRO POST");
                    console.log(JSON.stringify(error));  
                }  
            });
        }
    }

When executing gives me this error: inserir a descrição da imagem aqui

This code is being used for items that are stored on the Sharepoint Pages and in a document library. The code works correctly for the Pages list, but for the document library does not. I’ve seen Listitementitytypefullname from the Pages list and it’s SP.Data.Paginasitem but it seems that Listitementitytypefullname does not work for document libraries. What I must do to make it work for both Pages and Document Library?

  • I found this answer, will it help you? https://sharepoint.stackexchange.com/questions/161344/create-list-item-by-restful

  • I appreciate the answer. The type of documents is "SP.Data.Documentsitem" but I can pass the SP.Data.Documentsitem and the SP.Data.Paginasitem?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.