Custom event triggers

It’s possible to trigger automations from the template code by defined conditions, existence of specific parameters or by submitting a form.

Trigger automations from forms

To trigger an automation we need to add the form parameter with name AutomatApi.AutomationEvent.Name the value of it should be the automation we want to trigger.

<!DOCTYPE html>
<html>

    <head></head>

    <body>

        <form method="post">
            <input type="hidden" name="AutomatApi.AutomationEvent.Name" value="da-at1-automation">

            <button type="submit">Save</button>
        </form>
    </body>

</html>

Trigger automations on page load

To trigger automation immediately when the page is rendered we can use the tools’ helper. Note that this means that the automation will always trigger when the page is opened.

{{ .Tools.AutomationEvent "da-at1-automation" }}

Trigger automations conditionally on page load

Sometimes we might want to trigger the automations conditionally on page load, for this the regular if conditions apply. Wrapping these into the conditions will only make the run when the condition is truthful.

<!-- The automation will only be triggered if there is a custom parameter called triggerMyAutomation in the request -->
{{ if .Data.Parameters.triggerMyAutomation }}
    {{ .Tools.AutomationEvent "da-at1-automation" }}
{{ end }}

Passing custom data to automation triggers

We can also optionally pass custom data to the automations in json format. This can be some specific id’s, codes etc. You can pass as many parameters as you want.

Also, there is option to define id of the automation event, which is useful when we need to ensure that automation process were executed only once during processing time. See example below for each option.

Forms

Note that the value should be in valid json format. The json helpers might be useful here.

<!DOCTYPE html>
<html>

    <head></head>

    <body>

        <form method="post">
            <input type="hidden" name="AutomatApi.AutomationEvent.Name" value="da-at1-automation">
            <input type="hidden" name="AutomatApi.AutomationEvent.ID" value="uuid-or-something">
            <input type="hidden" name="AutomatApi.AutomationEvent.Data" value='{"browser": "{{ .Browser.Name }}"}'>

            <button type="submit">Save</button>
        </form>
    </body>

</html>

On automatic load

Using the jsonSet helper will make this a bit simpler.

{{ .Tools.AutomationEvent "da-at1-automation" (jsonSet `{}` "browser" .Browser.Name) "uuid-or-something" }}

Reading the parameters on the automation

To access the parameters we use the regular automation request syntax (.Data.Automation.Request). Structure after the Request.Get is based on the json we sent as input.

{
    "postOperations": [
        {
            "IntLogApi.Api.Post.myRequest1": "v1/log",
            "IntLogApi.Api.Json.myRequest1.application": "da-custom-events",
            "IntLogApi.Api.Json.myRequest1.string.value.visited": "{{ dtCurrent.Unix }}", 
            "IntLogApi.Api.Json.myRequest1.string.value.browser": "{{ .Data.Automation.Request.Get "browser" }}"
        }
    ],
    "enabled": true
}