Workflows and SPServices

May 5, 2012 at 11:41 PM
Hi, I have a piece of code which uses the SPServices to update a list with information from another part of the site. This all works well, but the code only runs when a user hits a page that the code is on - e.g. a page with the code in a content editor web part. Is there a way to make the script run on a schedule without user interaction possibly through a workflow? Thanks in advance.
Coordinator
May 7, 2012 at 1:45 PM

This is one of the drawbacks of developing some types of functionality client-side. There's no "timer job" you can use to fire things off. It can only work upon some user action.

M.

May 8, 2012 at 11:32 AM

I guess it depends (Sorry Marc!). What do you want the code to do and or what does it do that you want it to run on a schedule? Is it a large piece of code? There are some ways to do this but it really does matter based on what you want to accomplish.

May 8, 2012 at 11:59 AM

At the moment the code gets a list of all of the recently modified files in the current site and all sub sites. It then out puts them to the screen so that users can see the file that was modified, the date of modification and also a link to the file.

This can take up to 5 or 6 seconds to populate each time the page is loaded, so what I was hoping to do was to run the above script on a schedule to get the list of files, and then add them to a new list as a link and then add a view of that list to the front page. This would speed up the process.

Is there a way of utilising the same functionality as the web services but server side?

Thanks.

Coordinator
May 8, 2012 at 12:22 PM
Edited May 8, 2012 at 12:47 PM

Why not just write the results into a list as a sort of cache? You could also store the date/time of the write and only requery if a certain time period has elapsed.

However, I would consider switching to a DVWP with DataSourceMode="CrossList" to do this. It will run server side and be quite fast, diminishing the need for "caching".

M.

May 8, 2012 at 12:38 PM

Hi Marc,

I was intending to write the results of the query to a list as a cache and then each time the script runs delete all items and repopulate the list. Then just show a view of the list on the front page. I just need a way to schedule the script to run so that the list gets repopulated every 10 minutes or so.

I was going to use a DVWP but my script is dynamic and picks up changes from all libraries in the current site and all sub sites. With no changes to the script it also picks up changes from all new sub sites and all new libraries. With a DVWP I have to create a connection to each library that I want to query don't I? I didn't think it was as dynamic as I wanted it to be?

Thanks.

Coordinator
May 8, 2012 at 12:46 PM

DataSourceMode="CrossList" will look at the lists across the scope as you define it, which can be the entire Site Collection. I have several posts on it. It's one of the more powerful capabilities of the DVWP.

M.

May 8, 2012 at 4:42 PM

Cool I've found a few posts and that looks like it may do it! I'll give it a go. I'm guessing this isn't a version specific feature and will work on SharePoint Foundation 2010 as well as SharePoint Standard 2010?

Thanks. 

Coordinator
May 9, 2012 at 3:57 AM

Yes, this method works identically in 2007 and 2010, any license.

M.

May 9, 2012 at 11:01 AM

Awesome, just managed to create the DVWP that can query all files updated in the last 1 day for the current site and all subsites. Works so much quicker as well, it's almost instant.

Cheers for pointing me in the right direction Marc!

May 9, 2012 at 11:13 AM
Nice! Can you provide a copy of the code including the style sheet? Would like to see it.

Sent from my iPhone

On May 9, 2012, at 6:01 AM, "micolahan"<notifications@codeplex.com> wrote:

From: micolahan

Awesome, just managed to create the DVWP that can query all files updated in the last 1 day for the current site and all subsites. Works so much quicker as well, it's almost instant.

Cheers for pointing me in the right direction Marc!

Coordinator
May 9, 2012 at 12:20 PM

Excellent. The right tool for the job!

A CQWP would also do this, but you might need to customize the XSL there, too, so I generally prefer the DVWP.

M.