Document update after not firing

Ashutosh Pandey asked on February 11, 2020 13:38

I'm working on Kentico 10. Our system have different resource types and different clients. For example:

When creating a page, in the form, we are selecting following- Tile: History ResourceType : Sports Client : GoaFootballClub

Now when saving this page, we are showing this in a tree like this:

Sports GoaFootballClub 2020 Feb History

Now, I'm able to do above in:

DocumentEvents.Insert.After += Document_Insert_After;

When somebody updates the page, they can choose different ResourceType and Client, Hence, I want to do the same on update. For this, I added code in:

DocumentEvents.Update.After += Document_Update_After;

But this method is never getting fired when I save the page.

If I move the code in:

WorkflowEvents.SaveVersion.After += SaveVersion_After;

Then it works, but sometimes multiple times.

I hope I was able to explain my problem. My question is why Document_Update_After is not getting fired.

private void Document_Update_After(object sender, DocumentEventArgs e)
{
    EventLogProvider.LogEvent(EventType.INFORMATION, "Update after", "update_after", eventDescription: "update version after");
    HandleDocumentUpdated(e);
}

Recent Answers


Dat Nguyen answered on February 11, 2020 14:34

If the page is under workflow, you'd need to handle the events from the WorkflowEvents class, like you've already done.

You mentioned it sometimes fires the event multiple times. That may be due to the recursive nature of handling an update event for a document that references itself or another page of the same page type.

To work around that, use recursion control, like so:

    private void Workflow_SaveVersion_After(object sender, WorkflowEventArgs e)
    {            
       string key = **unique key**;
       using (var rc = new RecursionControl(key))
       {
            //custom logic here
       }
    }

Now the event will only be handled once per update.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on February 11, 2020 16:05 (last edited on February 11, 2020 16:09)

Use WorkflowEvents.CheckIn.After instead. If your document is under workflow it could be touched internally multiple times - that might cause multiple events firing like update.

0 votesVote for this answer Mark as a Correct answer

Ashutosh Pandey answered on February 11, 2020 16:22

Hi @peter, I need to update the tree on Save

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on February 11, 2020 17:14

ScripHelper has a refreshtree method

0 votesVote for this answer Mark as a Correct answer

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