Document Event Handler

Delford Chaffin asked on August 19, 2015 00:27

Two questions, actually ...

First, here is a simplified version of my code:

public override void Init()
{
    DocumentEvents.Insert.After += Document_Insert_After;
    DocumentEvents.Update.Before += Document_Update_Before;
    DocumentEvents.Update.After += Document_Update_After;
}

private void Document_Insert_After(object sender, DocumentEventArgs e)
{
    EventLogProvider.LogInformation("DocumentEvents", "InsertAfter");
}

private void Document_Update_Before(object sender, DocumentEventArgs e)
{
    EventLogProvider.LogInformation("DocumentEvents", "UpdateBefore");
}

private void Document_Update_After(object sender, DocumentEventArgs e)
{
    EventLogProvider.LogInformation("DocumentEvents", "UpdateAfter");
}

Why do all of these events seem to fire twice when I save changes on the CMSDesk Form tab?

Second, is there a way to get the previous value of a field on this document type? I had thought to do something like this:

SessionHelper.SetValue("prevValue", e.Node.GetStringValue("FieldName", ""));

... in the UpdateBefore event and get the value back in the UpdateAfter event, but the value is always whatever I set the field (field type Multiple User Selector) to before I hit Save.

Thanks!

Correct Answer

Brenden Kehren answered on August 19, 2015 03:10

Hey Delford,

Not sure on the double post back but if you're performing a save within the event then it could give you that effect.

Try this to get the original values: e.Node.GetOriginalValue("ColumnName");

1 votesVote for this answer Unmark Correct answer

Recent Answers


Roman Hutnyk answered on August 19, 2015 19:47

Delfor,

for your second question, you might also save in before and read in after to/from document custom data field: e.Node.DocumentCustomData["somename"]

0 votesVote for this answer Mark as a Correct answer

Delford Chaffin answered on August 19, 2015 19:59

Thanks all,

Brenden's answer for my second question seems to work well. And I'm only doing what I need to do if the old and new values are different, thus alleviating the problem in the first question. I'm still not clear why it's posting twice, but at least I have a solution that means I'm not running all my code twice.

2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.