SharePoint Sharpener

Obsessively Sharpening SharePoint

Item.Update() vs. Item.SystemUpdate() – Post Service Pack 1

with 4 comments


Many of you have probably encountered the problem where a workflow triggers itself several times because the code carries out one or more Item.Update() commands. This can be extremely annoying because running extra workflows can be taxing on the server – even if you make sure that the extra workflows don’t make any changes to the element.

Then, you may have discovered Item.SystemUpdate() which in theory should rid the list of the all the extra instances of workflows because it doesn’t trigger an update event and thus flies under the radar of the workflow engine.

This seemed to work just fine for a while. Lately, however, it seems that SystemUpdate() has startet triggering events just like a normal Update().

 

Post Service Pack 1?

I found that many of my workflows now started behaving differently, i.e. they began triggering multiple instances of workflows.

It took me a while to realise that it probably was a “bug fix” in SharePoint SP1 that was causing the problem.

A glance at the documentation for SystemUpdate() reveals that events are indeed triggered:

image

There is no mention of SP1 but I assume that this was when the changes were made.

 

Solution

This is bad news for many developers but obviously a design decision at Microsoft so things probably won’t be changed back to the way they were.

From now on you have to make sure that your workflows only make changes to elements when needed. I.e. you need to only use Update() and SystemUpdate() when they are really needed and thereby minimise the number of redundant workflow cycles.

Alternatively, you could look into programming your own event handlers to obtain more granular control of when events are triggered. I may explore this subject in a future post.

Advertisements

Written by Thomas Sondergaard

January 8, 2009 at 8:53 am

4 Responses

Subscribe to comments with RSS.

  1. Hi Thomas, I ran into the very same thing and I know have to code my workflows to stop the event fire, do the update, then turn the event fire back on:

    Events oEvents = new Events();

    oEvents.DisableEvents();

    workflowProperties.Item.SystemUpdate(false);

    oEvents.EnableEvents();

    Shereen

    March 2, 2009 at 7:13 pm

    • Hi Shereen,
      I need to do exactly what you have explained here to stop all events from firing, update my workflow and then enable the events again. I have tried your code but have a problem with finding the namespace for “events”. Can you please explain how you used Events().

      santie

      July 21, 2009 at 9:03 am

  2. Thank you very much NetCobra!!!

    Vladimir

    September 2, 2010 at 1:03 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: