API Questions on Kentico API.
Version 6.x > API > GLobal Events View modes: 
User avatar
Certified Developer 11
Certified Developer 11
devken - 8/30/2012 9:28:29 AM
   
GLobal Events
Hi,

I have a new document type containing an image field. The document name should be the name of the image, so, I use Global Events.
When i insert a new document it works but not when I update it or with workflow operations.

[CustomDocumentEvents]
public partial class CMSModuleLoader
{
/// <summary>
/// Attribute class that ensures the loading of custom handlers
/// </summary>
private class CustomDocumentEventsAttribute : CMSLoaderAttribute
{
/// <summary>
/// Called automatically when the application starts
/// </summary>
public override void Init()
{
DocumentEvents.Update.After += Document_Update_After;
}

private void Document_Update_After(object sender, DocumentEventArgs e)
{
UpdateDocumentName(e.Node);
}

private void UpdateDocumentName(TreeNode node)
{
if (node != null)
{
if (node.NodeClassName.Equals("aa.GalleryImage"))
{
var imageGuid = ValidationHelper.GetGuid(node.GetValue("ImageSrc"), Guid.Empty);
if (imageGuid == Guid.Empty) return;

var am = new AttachmentManager();
var attachment = am.GetAttachmentInfo(imageGuid, CMSContext.CurrentSiteName);
if (attachment == null) return;
node.DocumentName = attachment.AttachmentName;
node.Update();

}
}
}
}
}


Thanks for any guidance...

Regards,

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 8/30/2012 9:34:02 AM
   
RE:GLobal Events
Hello,

WorkFlow events have different event handlers. The document isn't physically updated until it hits the published state. Then should your code be fired.

Best regards,
Boris Pocatko