This project has moved and is read-only. For the latest updates, please go here.

Get Pre-Last Item in SP2010 List

Dec 20, 2013 at 10:52 AM
Hi All please help!
i need to calculate the value of the field, adding to it the previous value of the same field.
i have SharePoint 2010 List with 2 field (Field1/number, Field2/date).
users via table post in this list 30-31 items per one time (Field2 = day on the currents month 01/12/2013, 02/12/2013....31/12/2013).
i set button on the page and want calculate value in Field1 like:
1 item: Field1='0'; //0
2 item: Field1="1item Field1"+Field1; //0+Current Field1 value
3 item: Field1="2item Field1"+Field1;
4 item: Field1="3item Field1"+Field1;
i cant use "Last ID-1"-method because users can remove items before calculate it.
may be use Field2? Last Date - 1 day?
Please help can i use SPUpdateMultipleListItems for it? How as one click recalculate all 30 items.
Sorry for my English...
Dec 23, 2013 at 3:19 PM
If you're allowing the users to edit the data in "Datasheet View", I believe there is little you can do to control the data. The SPServices functions are not designed to operate in the Datasheet View.

Dec 23, 2013 at 3:23 PM
+1 to Geoff's comment.

However, you could add a button (or link, or whatever) that, when clicked, kicks off code to grab the last n records, do the calculations in a loop, and update the items as you go along or at the end.

SPUpdateMultipleListItems will update a set of items with the same values, which isn't what you want here, but you could use it as a model.

Dec 24, 2013 at 1:52 AM
Edited Dec 24, 2013 at 2:15 AM
Thanks for answers, All!
I have to work with the "datasheet" view because that is needed at a time to make a large number of records. (hate this)
Ok SPUpdateMultipleListItems is not for me. but i still love SPServices for his versatility 8-)
sympmarc, in accordance with your recommendation i make this:
  1. On load page i get all need data in array
query_mm = "<Query>" + //my CAML with month
        "<OrderBy>" +
            "<FieldRef Name='Created' Ascending='FALSE'/>" + 
        "</OrderBy>" +
        "<Where><Eq>" +
            "<FieldRef Name='_x041c__x0435__x0441__x044f__x04'/><Value Type='Calculated'>12</Value>" + //december
        "</Eq></Where>" +

function getList(completeFunction){
    var query = query_mm;
    result = new Array();
        $().SPServices({ operation: "GetListItems", async: false, listName: "{fb58992a-4027-411e-9859-56328b461868}",CAMLQuery:query,
            completefunc: function (xData, Status) {
                $(xData.responseXML).SPFilterNode("z:row").each(function() {
                    var row = new Array();
                        row[0] = $(this).attr("ows_ID");     //id field    
                        row[1] = $(this).attr("ows_Title"); //my field for calculate
                        result[$(this).attr("ows_ID")] = row; //my array
                    if(completeFunction) completeFunction(result);

Array.prototype.clean = function(deleteValue){  //remove empty rows
    for (var i = 0; i < this.length; i++)
        if (this[i] == deleteValue)
            this.splice(i, 1);
    return this;
    alert('Data for December: (ID/Value) '+result.join("-")); // my data may be with "reduce" i modify this values
after that i have "result" array with all my data. (1-10, 2-42,...etc. ID-Value)
  1. With button click, I hope modify result and send in list via loop "UpdateListItems".
    If someone can help me I will be saved. How send in list array with "id-value" row.
Dec 27, 2013 at 9:35 AM
for (var i = 0; i < ListID.length; i++) {
                            try {       
                                operation: "UpdateListItems",   
                                async: false,
                                listName: "{fb58992a-4027-411e-9859-56328b461868}",
                                ID: ListID[i],
                                valuepairs: [["_x041d__x0430__x043b__x0438__x04", nalp_calc[i]],["Title","Сводка отдела"]],
                                    completefunc: function (xData, Status) {
                                        __doPostBack("", "");
                        catch (e) {alert('Script:' + e);}
this code update SP List. Source for update - two array ListID (with ID) and nalp_calc with data. Its work for me, everybody thanx