Posted on 07/08/2014 11:00:16
Hi Per
On the ItemArgs you have an Item property - that will give you access to the item and its field values.
There are 2 different notifications when an item is saved:
Notifications.Items.Saving is broadcasted before the item is persisted to db
Notifications.Items.Saved is broadcasted after the item is persisted to db
So you should use the Saving notification.
Something like this:
using Dynamicweb;
namespace Dynamicweb.Examples.CSharp.Notifications.Standard.Item
{
[Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.Items.Saving)]
public class ItemSavingObserver : Dynamicweb.Extensibility.NotificationSubscriber
{
public override void OnNotify(string notification, Dynamicweb.Extensibility.NotificationArgs args)
{
if (args == null)
return;
Dynamicweb.Notifications.Items.ItemArgs itemArgs = (Dynamicweb.Notifications.Items.ItemArgs)args;
itemArgs.ToItem(itemArgs.Item)["MyField"] = "New value";
//itemArgs.Item
//TODO: Add code here
}
}
}