SPListItem SystemUpdate, Alerts and Workflow
"When you call the SystemUpdate method, events are triggered and the modifications are reported in the Change and Audit logs, but alerts are not sent and properties are not demoted into documents."
This is not 100% true.
For example:
{
using (SPSite site = new SPSite("http://localhost/"))static void ReportState(string state, SPListItem item)
{
using (SPWeb web = site.RootWeb)
{
SPList list = web.Lists["All Cases"];
// Item change alert is not generated by SystemUpdate
SPListItem item = list.Items[0];
ReportState("Before", item);
item["Title"] = "SystemUpdate exsiting item "+item.ID;
item.SystemUpdate();
ReportState("After", item);
// Item created alert is generated by SystemUpdate
SPListItem newItem = list.Items.Add();
ReportState("Before", newItem);
newItem["Title"] = "SystemUpdate to create a new item";
newItem.SystemUpdate();
ReportState("After", newItem);
}
}
{
Console.WriteLine(state);
Console.WriteLine("Modified: {0}", item[SPBuiltInFieldId.Modified]);
Console.WriteLine("Modified by: {0}", item["Modified By"]);
Console.WriteLine("Created: {0}", item[SPBuiltInFieldId.Created]);
Console.WriteLine("Created by: {0}", item["Created By"]);
Console.WriteLine();
}
The item change alert will not be triggerred by the first SystemUpdate call, but when a new item is created by calling SystemUpdate, the new item alert will be triggerred.
Before
Modified: 7/21/2010 11:49:52 AM
Modified by: 1;#Ethan Deng
Created: 7/16/2010 4:00:59 PM
Created by: 1;#Ethan Deng
After
Modified: 7/21/2010 11:49:52 AM
Modified by: 1;#Ethan Deng
Created: 7/16/2010 4:00:59 PM
Created by: 1;#Ethan Deng
Before
Modified:
Modified by:
Created:
Created by:
After
Modified: 7/21/2010 12:24:59 PM
Modified by: 1;#Ethan Deng
Created: 7/21/2010 12:24:59 PM
Created by: 1;#Ethan Deng
The same is true for triggerring workflow. The SystemUpdate() will triggerr Workflow that is set to be triggerred by "new item", but not the Workflow set to be tiggerred by "change".
Thank you. This post is very helpful. I wanted to know if SystemUpdate() would trigger workflows and this post answers this question.
ReplyDelete