Getting Started with Tridion Event System !!

Tridion Event System?

An Event Handler is a .NET assembly that uses the Event-System to hook into events that are occurring in the Content Manager. An Event Handler is triggered when an event occurs, like when a Component being saved or Page is published. In Tridion, most of the CMS features are event driven.

Why Event System?

  • Using Event System customization (business logic) can be performed on any particular event on the CMS itself. Below is an example:
    • OnComponentSavePre / OnComponentSavePost – Logic can be placed before / after saving any component (e.g. auto value population on fields, auto page & CP creation with the created component and publishing the same)
  • Automation of any CMS process (events) can be done. (e.g. Auto Publishing of pages based on some business logic)
  • Event system can be used with Tridion Workflow System for approval processes to be in place on event call.

event phases

Logic can be applied in any of the event phases as per the above pic:

Advantages of Event System

  • Using Event System, business logic can be placed on Content Manager End to avoid redundancy / complexity in the delivery end (i.e. Presentation Server).
  • If Business wants to perform any specific task (Custom logic automation) before publishing content from Tridion then event system will allow doing the same before pushing the content to database or file server.
  • Event system can be extended as and when required, as per business need.
  • Same can be extended in future to provide constructed solution to any such requirements rather than using any out of the box program.

Let’s see a practical scenario of using Event System along with workflow.

 

es

 

Code Sample with deployment steps:

You can perform a test run on event system deployment on the development server:

  • Designing and developing sample POC to set up Event System using Tridion’s API and .NET.
  • Configuration changes on CMS server to register the event system.
  • Testing the event system.

Now it’s time to get started with coding!!

Basic but Important, you must use the “Tridion.ContentManager.Extensibility.TcmExtension” namespace to get all required items to get started.

Create a class and define TcmExtension attribute that includes a unique ID for your Event Handler. We can have multiple Event Systems (dlls installed) with different TcmExtension attributes.

class

Subscribe the Event (with item type and Arguments in place). In this case event phase is Initiated as the event I am using is OnComponentSavePre. For post it will be TransactionCommited.

You must place the Subscribe() method inside class constructor as only this is getting called when events are triggered.

constructor

Then the Subscribe method as below.

subscribe

Write Custom Logic for your Event now as required. I have put a very simple logic just to get started.

OnCOmpSavePre

Here, the title of Components which are based on Schema ‘EventSystem’ will be changed dynamically when the mentioned event will be fired.

Now, Build your project and you should see the following in Output window:

1>------ Build started: Project: EventSystemTest, Configuration: Debug Any CPU ------
 1> EventSystemTest -> C:\Tridion\Projects\EventSystem\EventSystemTest\bin\Debug\EventSystemTest.dll
 1> Running Code Analysis...
 1> Code Analysis Complete -- 0 error(s), 0 warning(s)
 ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Once your dll is ready you need to install / register it on the CMS server itself.

Steps to Register Event System dll :

  1. Copy the DLL on the CMS server
  2. Register the event class by updating the C:\Tridion\Config\Tridion.ContentManager.config file

<extensions>
<add assemblyFileName=”C:\Program Files (x86)\Tridion\bin\ EventSystemTest.dll”/>
</extensions>

  1. Restart the following on CMS server
  • Tridion COM+
  • Tridion Content Manager Service Host service
  • Tridion Content Manager Publisher service

Now you are set to test your Event System. Go ahead in Tridion GUI and create one Component with the Schema (You can change the schema name as your wish) and then it should work. If any errors come up put some logging logic (Event Viewer) in the code and also you can debug in Visual Studio by attaching to Process (dllhost.exe / TcmPublisher.exe) to see the actual error.

Use this template and write your own custom logic to start your first Event System!!

Check more on Event System from here SDL Live Content (login required).

Happy Coding !!