Handling marketing automation triggers
You can influence trigger processing when a Marketing automation process is starting using the ProcessTrigger handler. For example, you can use the handler to penetrate activity data into the trigger macro resolver. This then allows you to create macro conditions that start a Marketing automation process, for example, based on the data submitted by a contact in a column of an online form.
Example
The following example demonstrates how you can penetrate online form submit activity data into a Marketing automation trigger macro resolver.
You have a Marketing automation process that subscribes contacts to a newsletter.
A triggers starts the process whenever a user submits the ContactUs form, as displayed in the following picture.
Now, you can improve the trigger to make it start the process only when users who use the “example.com” domain in the e-mail they submit to the form.
Assign a handler to the AutomationEvents.ProcessTrigger.Before event. The example uses a custom class in the App_Code folder:
using CMS.Base; using CMS.Automation; using CMS.DataEngine; using CMS.OnlineForms; using CMS.OnlineMarketing; using CMS.WebAnalytics; [TriggerHandler] public partial class CMSModuleLoader { /// <summary> /// Custom attribute class /// </summary> private class TriggerHandler : CMSLoaderAttribute { /// <summary> /// Called automatically when the application starts /// </summary> public override void Init() { // Assigns a handler to the AutomationEvents.ProcessTrigger.Before event AutomationEvents.ProcessTrigger.Before += ProcessTrigger_Before; } } }
Define the handler method (inside the custom CMSLoaderAttribute class):
void ProcessTrigger_Before(object sender, AutomationProcessTriggerEventArgs e) { // Processes trigger based on activity if (e.TriggerInfo.TriggerTargetObjectType == ActivityTypeInfo.OBJECT_TYPE) { // Gets activity from resolver var resolver = e.Options.Resolver; ActivityInfo activity = resolver.GetNamedSourceData("Activity") as ActivityInfo; if (activity != null) { // Checks if the activity represents form submit if (activity.ActivityType.EqualsCSafe("bizformsubmit")) { int formId = activity.ActivityItemID; int itemId = activity.ActivityItemDetailID; // Gets form BizFormInfo form = BizFormInfoProvider.GetBizFormInfo(formId); if (form != null) { // Gets the submitted form data var className = DataClassInfoProvider.GetClassName(form.FormClassID); BizFormItem item = BizFormItemProvider.GetItem(itemId, className); if (item != null) { // Makes FormData available in the trigger condition evaluation resolver.SetNamedSourceData("FormData", item); } } } } } }
Save the class. You can now use FormData in the trigger condition evaluation.
Change the trigger condition to:
FormData[“Email”].EndsWith(“@example.com”)
Submit the form using “@example.com” in the E-mail field.
The trigger automatically starts the process.