0

Below is the function and its fetching the Amount and uno but it throws an exception on clientContext.executeQueryAsync().

Here is the Code:

function delRec()

{
    var uno;
    var itemArray = [];
    var listItemEnumerator = collListItem.getEnumerator();
    var i=1;
    var amount = 0;
    var oListItem;
    var d = new Date();
    while (listItemEnumerator.moveNext())
    {
        oListItem= listItemEnumerator.get_current();
        if(document.getElementById('check'+i).checked==true)
        {
            amount=amount + oListItem.get_item('Amount');
            uno=oListItem.get_item('UniqueNo');
            alert(uno+' '+amount);
            oListItem.deleteObject();

            oListItem.update();

            itemArray.push(oListItem);

            clientContext.load(itemArray[itemArray.length-1]);
            alert(4);

        }
    }
    clientContext.executeQueryAsync(
                                    function (sender, args)
                                    {
                                        alert('record updated succesfully');
                                        updateAmount(amount,uno);
                                        //location.reload(true);
                                    },
                                    function (sender, args)
                                    {
                                        alert('Error: ' + args.get_message() + '\n' + args.get_stackTrace());
                                    });


}
  • It's because you have not loaded "collListItem" object. Please load that object before. – Dikesh Gandhi Jun 13 '16 at 12:21
  • yes i have loaded collListItem and i am able to update and insert new item but it is failing in delete – Shomit Jun 13 '16 at 13:08
  • If this is your code then collListItem is undefined. If you expect us to be psychic and know what you other code is, then I fear you will get a very low response rate here on StackOverflow – Danny '365CSI' Engelman Jun 13 '16 at 13:30
  • 1
    And by default I never answer questions using alert to debug code. If you want to call yourself a programmer, go and learn to use the F12 Debugger Console... which... will help you find the errors yourself and save you from waiting for an answer here. – Danny '365CSI' Engelman Jun 13 '16 at 13:34
  • hey buddy thanks but i know f12 debugging(i have checked the value of collistitem)....if wanted specs u could have asked it ...instead of typing rubbish.....thanks any way(i sorted it) – Shomit Jun 13 '16 at 18:31
0

i have found the problem...it is because after deleting item listItemEnumerator is getting.movenext() results in exception. changes made:

listItemEnumerator.moveNext();

                                                    while (listItemEnumerator.get_current())
                                                    {

                                                        oListItem= listItemEnumerator.get_current();
                                                        if(document.getElementById('check'+i).checked==true)
                                                        {
                                                            amount=amount + oListItem.get_item('Amount');
                                                            uno=oListItem.get_item('UniqueNo');
                                                            alert(uno+' '+amount);
                                                            listItemEnumerator.moveNext();
                                                            oListItem.deleteObject();
                                                        }
                                                        i++;                                                            i++;
                                                    }
                                                    oList.update();

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.