What is 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 is needed?
- 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.
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.
Following is a real time scenario for implementing Event System with Workflow.
Sample Project on Event System
for first time, 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.
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.
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.
Then the Subscribe method as below.
Write Custom Logic for your Event now as required. I have put a very simple logic just to get started.
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>
3) Restart the following on CMS server
-
- Tridion COM+
- Tridion Content Manager Service Host service
- Tridion Content Manager Publisher service
Now to test the code, open 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.
Check more on Event System from here SDL Live Content (login required).