Automation studio, Salesforce Marketing Cloud

How to Run an Automation in a Loop

How to Run an Automation in a Loop

As many of us are aware, automation in the Salesforce Marketing Cloud can only be scheduled to run at minimum once per hour. While this frequency may suffice for most automations created within the Automation Studio, there are instances where we may require an automation to run continuously, immediately after it completes its previous run.

Not forever, though. Nobody wants that, but at least it will, for example, process a huge number of records (millions).

To accomplish this, we will utilize a while loop and create two automations. The primary automation will act as the worker and execute the necessary tasks, while the secondary automation will solely serve to trigger the worker automation to restart the processing cycle.

This approach is particularly beneficial when handling Data Extensions with an extensive number of rows, often resulting in a run timeout if processed in one go. Alternatively, this method can be utilized in any other applications that necessitate immediate execution.

Prerequisites

Add following columns to data extension that will be processed in batches:

  • processed as Boolean
  • processed_at as date

Worker automation

Main automation that will process Data extension with a lot of data will consists of following activities.

  • query activity to take portion of data from the data extension you want to process in loop
  • verification activity – to finish automation while loop when there is no data to process
  • activities to process actual records taken into actual loop
  • mark records as processed so they wont be processed again in the original data extension
  • call the caller – this is script using to call other automation. For this you can find wast examples on the internet. You can achieve same with WSProxy or with platform function InvokePerform. Example can be found on stackexchange.
//InvokePerform simplified example
var obj = Platform.Function.CreateObject("Automation");
Platform.Function.SetObjectProperty(obj, "ObjectID", ObjectID);
var po = Platform.Function.CreateObject("PerformOptions");

var performResult = [0,0,0];
var performStatus = Platform.Function.InvokePerform(obj, "start", performResult, po);

//ws proxy sipmlified example
var WSProxy = new Script.Util.WSProxy();
WSProxy.performItem("Automation", { CustomerKey: customerKey }, "start");

Caller automation

Caller automation will consist of wait activity to make sure our worker automation is finished before we called it back to run again. And the script itself that runs the worker automation with method described earlier.

GOOD TO KNOW: Do not configure scheduler leave it blank. If you do so the automation could not be called from script

Oh hi there 👋
I have a FREE e-book for you.

Sign up now to get an in-depth analysis of Adobe and Salesforce Marketing Clouds!

We don’t spam! Read our privacy policy for more info.

#automation studio #JavaScript #programming #ssjs
Marcel Szimonisz
Marcel Szimonisz
MarTech consultant As a marketing automation consultant, I specialize in problem-solving, process automation, and driving innovation for clients' marketing platforms.

I hold certifications in Adobe Campaign v6 (3x certified) and Salesforce Marketing Cloud (5x certified), as well as 1x Salesforce Associate certified.

Moreover, I serve as a community advisor for Adobe Campaign, providing expert insights and guidance.

Beyond my professional pursuits, I explore various programming languages, CMSs, and frameworks, enhancing my technical expertise and staying at the forefront of industry advancements.
Take a look at our subscription offering in case you are looking for a Marketing Automation Consultant.

Leave a comment

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

Similar posts that you may find useful

Email Double opt in
Marketing Automation, Salesforce Marketing Cloud

Double opt-in with service cloud

14 minutes read

Double opt in is basically the must have process on any newsletter sign up page in any marketing automation tool. This will help you to establish cleaner email list of contacts, that most likely have given in their email address that they use. This will reward you with better deliverability rate. Double opt in process, […]

Continue reading
SFMC tips and tricks
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

The Power of Send Log in SFMC

1 minute read

Send log in Salesforce Marketing Cloud is a feature that allows you to track the delivery, open, click, and other engagement metrics for the emails that you send from your account. This feature helps you to gain insights into the performance of your email campaigns and optimize them for better results. When you enable send […]

Continue reading
SFMC tips and tricks
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Data views for transactional emails

1 minute read

Data views in Salesforce Marketing Cloud are very handy, when it comes to getting data insights from various sources inside the platform. I will give you a quick start on how to get data insights for you transactional emails using data views. We will use data from _Sent, _Job, and _Subscriber view s.TriggererSendDefinitionObjectID – object […]

Continue reading
Salesforce Marketing Cloud Tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Power of AMPScript Functions in SSJS

3 minutes read

Have you ever wondered, while working with SSJS, if there was a function in SSJS similar to the one you use in AMPscript? What if I told you that you can bring native AMPscript functions to SSJS? Today, I will show you how to incorporate the best features from both scripting worlds into SSJS automation, […]

Continue reading
Salesforce Marketing Cloud Tips
Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

Use client-side JavaScript in content block

1 minute read

Recently, I attempted to reference a content block from a cloud page that contained client-side JavaScript, and to my surprise, Salesforce Marketing Cloud removed it entirely. It looks like certain hook that triggers when you save your content block doesn;t like client side scripts and are completely removed like comments are when a executable program […]

Continue reading