---
title: Handling marketing automation triggers
related:
  - https://docs.kentico.com/k82/on-line-marketing-features/marketing-automation/setting-triggers-for-automation-processes.md
  - https://docs.kentico.com/k82/custom-development/handling-global-events.md
  - https://docs.kentico.com/k82/custom-development/handling-global-events/reference-global-system-events.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

You can influence trigger processing when a [Marketing automation](https://docs.kentico.com/k82/on-line-marketing-features/marketing-automation.md) 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](https://docs.kentico.com/k82/on-line-marketing-features/marketing-automation.md) process that subscribes contacts to a newsletter.

![Marketing automation process that subscribers contacts to newsletters](https://docs.kentico.com/docsassets/k82/handling-marketing-automation-triggers/example_process.png "Marketing automation process that subscribers contacts to newsletters")

A triggers starts the process whenever a user submits the _ContactUs_ [form](https://docs.kentico.com/k82/managing-website-content/forms.md), as displayed in the following picture.

![Trigger starts the marketing automation process when users submits a form](https://docs.kentico.com/docsassets/k82/handling-marketing-automation-triggers/process_trigger.png "Trigger starts the marketing automation process when users submits a form")

Now, you can improve the trigger to make it start the process only when users who use the "[example.com](http://example.com)" domain in the e-mail they submit to the form.

1. [Assign a handler](https://docs.kentico.com/k82/custom-development/handling-global-events.md) to the **AutomationEvents.ProcessTrigger.Before** event. The example uses a custom class in the App\_Code folder:

   ```csharp

   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;
           }
       } 
   }

   ```
2. Define the handler method (inside the custom **CMSLoaderAttribute** class):

   ```csharp

   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);
                       }
                   }
               }
           }
       }
   }

   ```
3. Save the class. You can now use _FormData_ in the trigger condition evaluation.
4. Change the trigger condition to:

   _FormData\["Email"].EndsWith("@example.com")_
5. Submit the form using "@example.com" in the E-mail field.

The trigger automatically starts the process.
