1

I've attempted to complete an update to a number column in a SharePoint 2010 list using JavaScript. I can update the title, or any other textbox field but not the number field. I have already attempted what was shown here... Updating number column in SharePoint programmatically

However, I have not been able to get any of the suggestions to work. I did arrive at the same assumption, that my type was wrong but every variation of changing type I have tried still does not work. Here is my code below.

function updateList(updatedArray){
    var siteUrl = '/my/site/';
    this.clientContext = new SP.ClientContext(siteUrl);
    this.oList = clientContext.get_web().get_lists().getByTitle('Testlist');
    console.dir(updatedArray);
    oListItem = oList.getItemById(7);
    oListItem.set_item('Order', 20);
    oListItem.update();

    /*$(updatedArray).each(function(){
        oListItem = oList.getItemById(this[1]);
        oListItem.set_item('Order', this[2]);
        oListItem.update();

        console.dir(oListItem);
    });  */

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

Order is the name of my number column. I did check it in JSON and that is the name shown. UpdatedArray is an array of list ids and new values for the Order column. The console print confirms the spots in the updatedArray I'm using are correct. As you can see I have even attempted to manually set the value.

I have tried using 20, 20.0, parseFloat("20"), parseFloat(20). The function returns with a querysucceed but no change on number columns. Number column is not set to unique. that's all the info I can think to pass on. Thanks in advance.

  • I forgot say I also tried parseInt('20'), Number('20'), parseInt(20), Number(20) – Ben Hester Jan 24 '18 at 18:29
2

You forgot a clientcontext.load() after the update call.

So it should be:

function updateList(updatedArray){
var siteUrl = '/my/site/';
this.clientContext = new SP.ClientContext(siteUrl);
this.oList = clientContext.get_web().get_lists().getByTitle('Testlist');
console.dir(updatedArray);
oListItem = oList.getItemById(7);
oListItem.set_item('Order', 20);
oListItem.update();

clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

  • So I'm not sure what happened. I attempted the above solution and nothing. I added a new number column called 'Blarg' and attempted to change that and it worked. I'm thinking the name 'Order' may be reserved or something. – Ben Hester Jan 24 '18 at 19:48
  • Took out the load and it still worked with my new column name. Just for clarification. – Ben Hester Jan 24 '18 at 19:56
  • Ah good call, Order is actually an internal field name: blogs.msdn.microsoft.com/michael_yeager/2008/11/03/… If you go to the list settings for your 'testlist' and mouseover the 'Order' field, you'll see in the URL what the internal name for the field is. In a case like this where there is a collision with internal Sharepoint field, the internal name for your field will probably be 'Order0'. Use that and your update should work. – GVIrish Jan 24 '18 at 21:43

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.