Notification for Paused Automations

Automations in Automation Studio have out-of-the-box notifications for when automations are skipped, an error occurs, or are successful in completing the automation. What automations don’t have is a notification for if an automation is paused.

Why is this important?

Use Case:

You need to make a change to an activity in a scheduled automation. For example, updating a SQL query in the automation. In order to make any changes to schedule automations, you need to pause the automation to make the edit. You make the edit and save the SQL query activity. But you forget to set the automation back to active. Days or weeks go by before you notice that the automation has not run.

Solution:

  • Build an “Automation Status” page in CloudPages using SSJS and AMPscript.
  • Use a Script activity to POST an email address to the CloudPage.
  • If the status of the automation is paused, insert a record into a data extension.
  • The record is injected into a journey in Journey Builder and sends the internal notification that the automation is paused.

Build an “Automation Status” CloudPage

This CloudPage will need to accomplish a few things:
1. Run a For Loop around a SSJS Retrieve Request to pull in the automation status and display on the CloudPage (assuming we want to monitor more than 1 automation)
2. RequestParameter for the EmailAddress to be used in the Journey
3. Conditional Statement around an InsertDE to update the data extension only when the automation is paused.

SSJS Retrieve Request

We will be using a Platform Function of “RetrieveRequest” so there is no need to load the core library shown below. You probably seen this platform load code below and have added it to the top of your SSJS code. You actually don’t need to load the core library if you can use platform function.

Platform Server-side JavaScript functions allow you to use standard JSON and JavaScript functionality to interact with the Marketing Cloud platform. Platform objects can function within email messages, mobile messages, CloudPages, microsites, and landing pages. Because platform objects exist outside of the core library, you can realize faster performance than with other Server-side JavaScript functions.

					


First we’ll need to use the BuildRowSetFromString function for the automation keys. And also start the For Loop based on that rowset.

					

%%[
Set @queryparams = BuildRowsetFromString(‘Automation1Key-xxxx-xxxx-xxxxx-xxxxxxx,Automation2Key-xxxx-xxxx-xxxxx-xxxxxxx’)
for @i = 1 to Rowcount(@queryparams) do
  Set @row = Row(@queryparams, @i)
  Set @automationKey = Field(@row,1)

]%%

Next is the bulk of the coding which is the SSJS Retrieve Request. In the code below, we’re taking the @automationKey that we’ve hardcoded in the BuildRowSetFromString function and setting that variable in SSJS using platform variable.

Then we’re retrieving the automation using the CustomerKey and filtering on the automationCustomerKey SSJS variable. Lastly, we will need the Status as an AMPscript variable to be used later.

					


RequestParameter for EmailAddress

The RequestParameter function will be used for the email address recipient of the paused automation notification. The goal is to use a POST action from a SSJS activity in Automation Studio and pass that email address value to the CloudPage. Then the CloudPage will use the RequestParameter function to insert into a data extension using the InsertDE function.

					

set @emailAddress = RequestParameter(“emailAddress”)

IF Conditional Statement and InsertDE

The next step that we’ll want on this Automation Status CloudPage is an InsertDE for when the automation has a status of paused. Also we’ll want to wrap that InsertDE with an IF function. We wouldn’t want the InsertDE firing every single time the page is loaded. We only want the notification sent if the automation is paused and if we have an email address to send the notification to (notice the commented out Code Statuses in the SSJS Retrieve Request above).

					

set @guid = GUID()
IF @emailAddress != “” AND @status == “4” THEN
 InsertData(“Automation_Status”, “EmailAddress”, @emailAddress, “AutomationKey”, @automationKey, “AutomationName”, @automationName, “Status”, @status, “StatusDesc”, @statusDesc, “GUID”, @guid)
ENDIF

You’ll notice that I also put in a GUID function to insert a GUID into the data extension. The reason for this is to have a Primary Key on the data extension since we may be sending the Automation Status notification to the same email address every time it’s paused.

Also there are some other variables in the InsertDE such as the @statusDesc and @automationName. These are just friendly names for the Status Code and CustomerKey of the Automation. I simply wrapped those around IF statements and populated those values into the respective variables.

Lastly, I just use the V function to list out the Automation Status details on the CloudPage and close out the For Loop.

					

Automation Name: %%= v(@automationName) =%%
Automation Key: %%= v(@automationKey) =%%
Status: %%=v(@Status)=%%
Status Desc: %%=v(@statusDesc)=%%

%%[ next @i ]%%

I’ll write a separate instructional guide for sending the notification via Journey. The tutorial will cover the basics of Journey Builder and can be applied for this Automation Status notification.

I posted an idea in Salesforce IdeaExchange to add an out-of-the-box solution for a Notification for Paused Automations in Automation Studio

Leave a Reply

Your email address will not be published. Required fields are marked *