0

I have this code that I always use to query and display items, but I need to perform occasional updates as well and tried this code.

It wouldn't update or recognize the word update. I tried a number of ways but this is where I am now:

function getListUP() {
 try {
        var clientContext = new SP.ClientContext.get_current();
        var web = clientContext .get_web();
        var list = web.get_lists().getByTitle('TestList');
        var query = '<View Scope=\'RecursiveAll\'>'+
                        '<Query>'+
                            '<Where>'+
                              '<Eq>'+
                                 '<FieldRef Name=\'ID\'/>' + 
                                 '<Value Type=\'Text\'>'+ itemID +'</Value>'+
                              '</Eq>'+
                            '</Where>'+

                        '</Query>'+
                       '</View>';
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml(query);
        this.listItems = list.getItems(camlQuery);
        clientContext.load(listItems,'Include(Title,ID,Status)');
        clientContext.executeQueryAsync(Function.createDelegate(this, this.querysuccessN), Function.createDelegate(this, this.onQueryFailed));
    }
catch (e) {
        alert(e);
    }
}
function querysuccessN() 
{alert(1);
var listItemInfo = '';
    var listItemEnumeratorN = listItems.getEnumerator();

 while (listItemEnumeratorN.moveNext()) 
    {
     var oListItem = listItemEnumeratorN.get_current();
     var Reg = oListItem.get_item('Title');
     var Reg1 = oListItem.get_item('Status');
     if(Reg1 == 'Open'){
     alert(2);
     this.set_item('Status', 2);
     alert(3);
     this.listItem.update();
     this.context.executeQueryAsync();
     alert("Update Success");}
}

It passes through to the 3rd alert and sometimes gets the success but it never actually updates the list with the information I want.

I just want to change a dropdown item to go from Open to Reviewed or In-Progress on a single record.

0

Why do you call:

this.set_item('Status', 2);

instead of:

oListItem.set_item('Status', 2);


Also, why do you call:

this.listItem.update();

instead of:

oListItem.update();


And also: don't use the Id of the choice value you want, but directly the string value. So the set_item call should actually be:

oListItem.set_item('Status', 'Reviewed');
  • I tried both and neither worked real well. It was duplicating so I added a delete in the array for each item and each time it was read. However, it still duplicated. So using the this.listItem seemed to solved the multiple items but only for the first 200 records updated. After that it started to duplicate again. Since there were too many issues we changed our whole direction and went to greenplumb and angular – Richard Przybylski Feb 22 '16 at 16:53

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.