API
Version 7.x > API > How do I update a field when using DocumentEvents.Update.Before. View modes: 
User avatar
Member
Member
Boolean - 4/26/2013 1:22:01 PM
   
How do I update a field when using DocumentEvents.Update.Before.
Hi all

I'm currently using the following global event:

DocumentEvents.Update.Before += MySite_Update_Before;

When I catch that event, there are a few fields I need to update when the user attempts to save the document (for example, there's a few fields that need to be marked as false depending on how the form was completed). I've run into two issues though:

1) If I use "node.SetValue("ValueToUpdate", false);", it updates the database but does not appear as changed in the CMS Desk. I suspect because we have versioning turned on it's still pointing to an older version.

2) To fix this, I attempt to call "node.Update()" or "DocumentHelper.UpdateDocument(document, tree, );", but this triggers my global event again, causing Kentico to spiral forever into an infinite loop.

So I guess my question is two part. One being, if I set a value in a global event, is there something else I need to do to get it to appear in Kentico? And two, if I need to call some sort of update on the node/document, how do I avoid Kentico getting stuck in a loop.

Thanks!

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 4/27/2013 10:15:56 PM
   
RE:How do I update a field when using DocumentEvents.Update.Before.
Hi,

Could you please explain what exactly are you trying to achieve?

Generally you dont need to call any kind of update after the value is saved into the db to see the changes in the CMS Desk. This may be due to some dependencies.

To check if this is the case. Could you please delete all older version of the document that you want to see changes in and see if the value you set is displaying correctly?

Also I'm not sure what fields are you updating, but I would highly suggest you to go to Site Manager -> Support -> API examples. E.g.. in document section there are some examples of how to update the document name etc.

Let me know if you need further assistance.

Kind regards,
Richard Sustek

User avatar
Member
Member
ndeych-gmail - 5/15/2013 12:35:04 PM
   
RE:How do I update a field when using DocumentEvents.Update.Before.
Hi,

Were you able to solve your issue? I am having the same problem and was wondering if you figured it out.

Thanks!

Natalie

User avatar
Member
Member
ndeych-gmail - 5/15/2013 12:44:17 PM
   
RE:How do I update a field when using DocumentEvents.Update.Before.
I was able to get it to work for update using WorkflowEvents
in init()
 WorkflowEvents.SaveVersion.Before += Update_Index;

void Update_Index(object sender, WorkflowEventArgs e)
{
e.Document.SetValue("DocumentPageKeywords", fileContent);
}