Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a feature receiver which batch updates a particular field / column in my list. Code is provided below.

NB: This is very simple list item batch processing code which I got from http://msdn.microsoft.com/en-us/library/cc404818(v=office.12).aspx. I do this instead of looping through the entire list because it has 1000s of rows.

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        using (SPWeb web = properties.Feature.Parent as SPWeb)
        {
            SPList list = web.Lists["MyList"];
            SPQuery query = new SPQuery();
            query.RowLimit = 100;

            do
            {
                // Get the next batch of 100 uninitialised items.
                SPListItemCollection uninitialisedItems = list.GetItems(query);

                // Batch update the list items.
                StringBuilder methodBuilder = new StringBuilder();
                string batchFormat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                    "<ows:Batch OnError=\"Continue\">{0}</ows:Batch>";
                string methodFormat = "<Method ID=\"{0}\">" +
                        "<SetList>{1}</SetList>" +
                        "<SetVar Name=\"Cmd\">Save</SetVar>" +
                        "<SetVar Name=\"ID\">{2}</SetVar>" +
                        "<SetVar Name=\"urn:schemas-microsoft-com:office:office#MyField\">{4}</SetVar>" +
                    "</Method>";

                for (int i = 0; i < uninitialisedItems.Count; i++)
                {
                    int itemID = uninitialisedItems[i].ID;
                    methodBuilder.AppendFormat(methodFormat, itemID, list.ID.ToString(), itemID, 1);
                }

                // THIS IS THE LINE THAT IS CAUSING MY ALERTS TO BE SENT.
                list.ParentWeb.ProcessBatchData(string.Format(batchFormat, methodBuilder.ToString()));

                query.ListItemCollectionPosition = uninitialisedItems.ListItemCollectionPosition;
            } while (query.ListItemCollectionPosition != null);
        }
    }

The problem here is that an email alert is being sent for every one of my list items saying that it has changed. I want to prevent this alert from being sent as I am merely setting a field that is not made visible to the user. Any idea how to do this?

FYI: I am using MOSS 2007

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

You could use SystemUpdate instead of ProcessBatchData. False should mean modified date doesn't change:

SPListItem item = ???;
item["myField"] = "my value";
item.SystemUpdate(false);

Of course, this means you have to update each item one at a time instead of the batch process which may lead to performance issues.

See also, how to temporarily disable email notification while updating items in code?.

share|improve this answer
    
Works like a charm. –  Nick Larter Dec 16 '11 at 7:54
add comment

If ProcessBatchData is required due to performance/load constraints, you can programmatically disable alerts by iterating through SPWeb.Alerts and finding those associated with your list.

This answer gives a good code example for this: Deactivate email-notifications for SPLists only temporally (and programmatically)

This is applicable in SP2007 (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.alerts(v=office.12).aspx)

share|improve this answer
    
I had actually considered this @Russell, however the list I am updating is a large tracking list which gets used almost constantly by other employees. So whilst your solution would work from a technical standpoint, we didn't want to disable the alerts that users should be getting (during regular day-to-day list activities) and therefore affect the business. NB: our list has thousands of rows and so takes roughly twenty minutes to update, so the system would then be "down" for this time. We wanted the change/upgrade to be completely transparent to the end user and not affect their work. –  Nick Larter Dec 22 '11 at 5:13
    
Thanks for the clarification. It appears in your case, as you say, the approach from Kit was the best. Hopefully this answer will help in other scenarios too. :) –  Russell Dec 22 '11 at 5:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.