SPUpdateMultipleListItems and the dreaded [today]

Nov 15, 2010 at 6:15 PM

With the latest release of SPServices (0.5.8), I noticed this new SPUpdateMultipleListItems.  Or maybe it has been there, and I did not notice!

Does anyone think this may be a crude way for those of us who do not have the ability to use Sharepoint Designer to keep a column relatively updated with a value =[today]?

Maybe on any page with a view to this particular list, drop in a cewp - have SPUpdateMultipleListItems look for list items where the column "2Day"s value is not equal to today, and update the list items with the current value of today?  That way "2day" could be involved in calculated columns, etc.  I know it is a bit crude, but what are you going to do!!

I am a hack at javascript, but will give it a try - if anyone comes up with a clean solution, please drop a copy here!!

Nov 16, 2010 at 3:59 PM

OK - here is what I came up with that works - use your list & column name values and references to jQuery and SPServices.  I did not have it compare to see if date was already current, but this is a start.

Does anyone know if this can be done with listName blank or an array so any/multiple lists on the site with column named "today" are updated?

But, this one works (in my example the list name is "SampleList" and the column name is "today":

<SCRIPT type=text/javascript src="/sites/rc/mastercode/jquery.current.min.js"></SCRIPT>

<SCRIPT type=text/javascript src="/sites/rc/mastercode/jquery.SPServices-0.5.8.min.js"></SCRIPT>

<SCRIPT type=text/javascript>

$(document).ready(function() {

//getting today's date and formatting yyyy-mm-dd to match SP
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
curr_month = curr_month + 1
var curr_year = d.getFullYear();
var today = (curr_year + "-" + curr_month + "-" + curr_date);

//using SP Services to update all items in list for column today to today's date
//be sure column name is "today" and if list name has spaces, use the GUID instead in the format {xxxx-xxxxx.....}

  listName: "SampleList",
  CAMLQuery: "<Query><Where><Geq><FieldRef Name='ID' /><Value Type='Counter'>1</Value></Geq></Where></Query>",
  valuepairs: [["today", today ]]

Nov 16, 2010 at 8:33 PM
Edited Nov 16, 2010 at 8:40 PM


This is one of those things that might do what you want, but I'm a little wary of it as a method. Here are some reasons why:

  • To update your today column, you have to navigate to the page so that the script will run.
  • The script will run after the page loads in the browser, so any view you are looking at will reflect the prior value of today.
  • Any workflows you have in place on the items will kick off on the update.
  • You will also be changing the Modified and Modified By column values to the current user on every page load.

I think it basically falls into the category of "hack", though it might work just fine for you if you are careful. I think in actual use it may fall apart given the concerns I list above soI wouldn't recommend this approach. Using SharePoint Designer-based workflows or timer jobs would be far more robust and less likely to cause issues. Of course it also depends on what you are using the today column for, which you don't fully explain.


  • SPUpdateMultipleListItems is a new function I just added in as of v0.5.8. The underlying Lists Web Services operations have always been there to build it, of course, but I only just added it in.
  • List names with spaces are fine; you don't need to use the GUID, but you can if you choose to.
  • I built the function to take only one listName. I certainly didn't predict the use you're trying here!


Oct 9, 2012 at 6:27 PM
Edited Oct 9, 2012 at 7:35 PM

Hey sympmarc,

lol, I'm actually in the process of using your SPUpdateMultipleListItems for doing the same thing to keep my today calculations in sync with the current date.

I just can't figure out a way to have it update before the page loads so I don't have to refresh the sharepoint web part page to see the results.

I've tried doing an auto-refresh but that kind of breaks things in the page for some reason.

The reason I'm doing it this way is that I don't have access to the server to build a timer based job to initiate the workflow. Also, the workflow I attempted to get the fields to update without a timer service just went into a infinite loop.

Any suggestions?

Oct 10, 2012 at 1:12 PM

You could do the update and then simply redirect to the same page:

window.location = window.location.href;


Oct 10, 2012 at 3:41 PM

won't that put it in a recursive page loop if there are no hash or query tags to detect and stop the next redirect? As soon as it redirects to itself it will run the SPUpdateMultipleListItems and redirect again.

I have tried this redirect method using the hash and query tags to detect and stop the next redirect but for some reason the sharepoint page can't handle those tags in the url and it breaks functionality within page.

Oct 10, 2012 at 3:44 PM

You'd have to add something conditional in your script, yes. Simply adding a Query String parameter you can test should do it, like



Oct 10, 2012 at 3:54 PM
Edited Oct 10, 2012 at 3:56 PM

I did have a question however about your SPUpdateMultipleListItems. I found out some interesting things about how it's being executed that may explain why I can't get it to run before the page load. I found this little tid bit on a site called "5 Things You Might Not Know about jQuery"

1.You don't have to use $(document).ready() anymore, though you'll still see plenty of code out there that does. If you want to run a function when the document is ready to be manipulated, just pass that function directly to $().

By the above statement executing your SPUpdateMultipleListItems like the below sample from your documentation will always result in it waiting for the page to load.


The same would be true for executing it like the following since $ is just a shortcut for jQuery


My question is how would you execute SPUpdateMultipleListItems differently than above so that it will run before the page loads?


David Infante



Oct 10, 2012 at 4:04 PM

You can't. The paage is assembled on the server and script runs client side. By the time the script *can* run, the page already has all of its data on it.


Oct 10, 2012 at 4:07 PM

I see, thanks for the info. I really appreciate it :D