我有一个包含 30 奇数列的列表。
我已将两个事件处理程序附加到列表中。1. 项目更新 2. 项目更新
在 ItemUpdating 事件中,我正在检查一个字段值是否有更改。
在 ItemUpdating 事件中,如果值发生变化,我想进行处理。我不能在这里进行比较,因为之前的属性不提供列表项中的旧值。
处理包括少量工作和完成后发送电子邮件。
我正在寻找一种解决方案,当 ItemUpdating 中的字段值发生变化时,我可以设置该位。如果设置在 ItemUpdated 中进行处理,请检查该位。
我有一个包含 30 奇数列的列表。
我已将两个事件处理程序附加到列表中。1. 项目更新 2. 项目更新
在 ItemUpdating 事件中,我正在检查一个字段值是否有更改。
在 ItemUpdating 事件中,如果值发生变化,我想进行处理。我不能在这里进行比较,因为之前的属性不提供列表项中的旧值。
处理包括少量工作和完成后发送电子邮件。
我正在寻找一种解决方案,当 ItemUpdating 中的字段值发生变化时,我可以设置该位。如果设置在 ItemUpdated 中进行处理,请检查该位。
您将无法直接共享值,您将不得不使用辅助方法来保存数据。
最简单的方法是使用列表项的属性包。
//the list item you want to update (typically SPItemEventProperties.ListItem in an event receiver
SPListItem specialItem = list.Items[0];
specialItem.Properties["some_persisted_key"] = "Some Value here";
specialItem.SystemUpdate(false);
请务必使用,SystemUpdate否则您会遇到创建无限循环的危险(或如该文章中所述预先禁用事件触发)。
在您的ItemUpdated事件中,您可以访问您的价值,然后只需访问specialItem.Properties["some_persisted_key"].
这是对我有用的完整解决方案......非常感谢@moontear!
它允许我使用当前的 items 属性包并每次都使键无效,因此它不会保留值。
public override void ItemUpdating(SPItemEventProperties properties)
{
SPListItem currentItem = properties.List.Items.GetItemById(properties.ListItem.ID);
//I had to null out the key or I would have conflicts the next time the event is triggered
currentItem.Properties["DateChanged"] = null;
currentItem.SystemUpdate(false);
currentItem.Properties["DateChanged"] = true;
currentItem.SystemUpdate(false);
}
public override void ItemUpdated(SPItemEventProperties properties)
{
if (Convert.ToBoolean(Convert.ToBoolean(currentItem.Properties["DateChanged"]))
{
//do something
}
}
在主列表中创建一列,其中值是更改,例如“OLDVALUES”。properties.ListItem["OLDVALUES"]=Value1+";" +Value2+";" +Value3+";";使用in事件设置该字段ItemUpdating(使用等值获取 Value1、Values2 和 Value3 properties.ListItem["Value1"])。
现在在项目更新中,使用 like
string oldValue = properties.ListItem["OLDVALUES"].ToString();
and slip in array and then you can set global variables and access them in your code. Remember its a SandBox solution approach for event receivers, not for farm solution.
Enable Item version (optionally max to 2 or 5)
and on ItemUpdated use:
object oldValue = properties.ListItem.Versions[1]["FieldName"];
object currentValue = properties.ListItem.Versions[0]["FieldName"];
The versions index 0 will always return the current item version.(this happened for my test with about 5 modifications, I recommend test it again :) )