0

I tell you that I have been fighting with this bug a few days ago. He is winning ... On the EditForm I have a grid that points to another sherpoint list. I can add listitems to that other list or edit those already loaded. When saving the EditForm via JSOM, I save the changes in the item corresponding to the form and also in all the list items in the grid. According to the type of field, it is how you set the value. I use set_item (internalName, value) and then the update. To set the values ​​I go through an array of key value objects, the key being the internal name. I capture the error with a try catch and it is given in the set_item, then I leave what it prints in the console.

Maximum call stack size exceeded     RangeError: Maximum call stack size exceeded
at Function.Object$getType [as getType] (ScriptResource.axd?...)
at Object.Sys$_isInstanceOfType [as _isInstanceOfType] (ScriptResource.axd?...)
at Function$_validateParameterType [as _validateParameterType] (ScriptResource.axd?...)
at Function$_validateParameter [as _validateParameter] (ScriptResource.axd?...)
at Function$_validateParams [as _validateParams] (ScriptResource.axd?...)
at Function.Type$inheritsFrom [as inheritsFrom] (ScriptResource.axd?...)
at Object.Sys$_isInstanceOfType [as _isInstanceOfType] (ScriptResource.axd?...)
at Function$_validateParameterType [as _validateParameterType] (ScriptResource.axd.....)
at Function$_validateParameter [as _validateParameter] (ScriptResource.axd?....)
at Function$_validateParams [as _validateParams] (ScriptResource.axd?...)

It is not always given to me when I set the same type of field, so I think it should not be, apart from the list item of the EditForm I do it in the same way and the bug does not jump.

Thank you very much for your time, regards.

UPDATE:

Here is the code

function updateItemProperties(itemId, obj) {
var auxDef = $.Deferred();
var list = ListItems.getListByURLSynchronous(ctx, siteUrl, obj.list);
var item = list.getItemById(parseInt(itemId));
try {
    for (var i = 0; i < obj.data.length; i++) {
        if (obj.data[i].name === 'ID' || obj.data[i].name === 'Attachments') continue;
        else {
            console.log('Set ' + obj.data[i].name + ' value:  ', obj.data[i].value);
            item.set_item(obj.data[i].name, obj.data[i].value);//HERE IT BREAKS
        }
    }
    item.update();
    if (typeof obj.attachments !== 'undefined' && Object.keys(obj.attachments.urls).length > 0) {
        var attachmentsUpCount = 0;
        var attachmentsDelCount = 0;
        for (var name in obj.attachments.urls) {
            var aux = obj.attachments.urls[name];
            if (aux.action === 'new') {
                attachmentsUpCount++;
                var listName = ListItems.listCacheWhitTitle[obj.list].get_title();
                uploadFileSP(listName, itemId, aux.name, aux.file).then(function () {
                    attachmentsUpCount--;
                    if (attachmentsUpCount === 0 && attachmentsDelCount === 0)
                        auxDef.resolve();
                }, function () {
                    auxDef.fail(arguments);
                });
            } else if (aux.action === 'delete') {
                attachmentsDelCount++;
                var attachments = obj.attachments;
                for (var j = 0; j < attachments.get_count() ; j++) {
                    if (attachments.itemAt(j).get_name() === aux.name) {
                        attachments.itemAt(j).deleteObject();
                        attachmentsDelCount--;
                    }
                }
            }
        }
        if (attachmentsUpCount === 0 && attachmentsDelCount === 0)
            auxDef.resolve();
    } else {
        auxDef.resolve();
    }
} catch (args) {
    console.error('Error try catch updateProperties. ' + args.message + '    ', args);
    auxDef.reject(arguments);
}
return auxDef;}

Solved! Taking into account the comment of LZ_MSFT and although I thought that the error was not in the values ​​that it set ... It was not like that. When using a new library to handle the lookups when I got the value of it and set them it was not coming with the form 'Id # Value' so I had a validation error! And falling into the cath and breaking the promise, the data was never sent to the server and I could not account. It was a few days! Thanks

For the registration: I do not have problems for making set_item of more than one field.

1 Answer 1

0

It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you hit the call stack limit.

I suggest you provide the JSOM code for further research.

We can also use REST API to update list items.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
var listName="CustomList";
var itemId=1;
function UpdateListItem(){
    var itemType = GetItemTypeForListName(listName);
    var item = {
        "__metadata": { "type": itemType },
        "Title": "test"   
    };

    $.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_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) {
            console.log('Success');
            //window.location.href=window.location.href;
        },
        error: function (data) {
            console.log("Error");
        }
    });
}
// Get List Item Type metadata
function GetItemTypeForListName(name) {
    return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}  
</script>
<input type="button" onclick="UpdateListItem()" value="Update"/>
4
  • just modify the question with all the code
    – rockodg
    Mar 14, 2019 at 17:52
  • Check the value of the obj.data[i].name and obj.data[i].value, and check which type of the field. What the count of obj.data.length? If you have a lot of fields, as a workaround, we can update item properties every 5 one time.
    – LZ_MSFT
    Mar 15, 2019 at 1:22
  • The value of the data corresponds to the type of field. The number of fields varies according to the list, the average is 10 fields. You say I can not do the update for more than 5 fields? In the documentation I could not find anything of the subject, do you know of any place to look or is it an experience?
    – rockodg
    Mar 15, 2019 at 13:08
  • Try to use REST API to set fields, and check if it works.
    – LZ_MSFT
    Mar 18, 2019 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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