0

I have this code below:

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));  
                }  
            });
        }
    }

I'm using this code to insert User ID in the "Pages" list and a library that I created, but they've different content type associated. When I run this code displays an error: enter image description here

0

It looks like you have passed wrong List Entity type name. you can find your list entity name using following URL:

https://yoursite/_api/web/lists/getbytitle('List Name')?$select=ListItemEntityTypeFullName

  • Does document library have a ListItemEntityTypeFullName? – KmDroid Jan 2 at 11:59
  • Yes, It does have – Hitendra Solanki Jan 7 at 10:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.