Retrieving and Starting an Automation with SSJS

Server-side Script (SSJS) Activities are a hidden gem of the Salesforce Marketing Cloud. They’re useful for a wide range of applications. I ran into a scenario where I wanted to run an Automation programmatically — if it’s not already running.

It was way harder than it needed to be. Hope this saves you some frustration:

The retrieve is for getting the ObjectID and Status of the Automation, which you then use to check to see if it’s running and then invoke a Perform if it isn’t.

The frustrating part of this was that the ObjectID is not a retrieveable property of the Automation Object (unlike Status). It’s only returned in the result-set of a successful Retrieve.

I’d suggest testing this script in a Landing Page until you get it working and then move it to the Script Activity.

SFMC Support can enable Script Activities if there’s not a Script entry in the Interactions drop-down menu.

For further reading:

Leave a Reply

9 Comments on "Retrieving and Starting an Automation with SSJS"

Notify of
Sort by:   newest | oldest | most voted
Victor Corey

How would you start an Automation in a Child BU? I tried adding

var cid = Platform.Function.CreateObject(“ClientID”);
Platform.Function.SetObjectProperty(cid, “ID”, “xxxxxxx”);
Platform.Function.SetObjectProperty(cid, “IDSpecified”, true);
Platform.Function.AddObjectArrayItem(rr, “ClientIDs”, cid);

before the Simple Filter Part but still getting automation not found?


I’m looking to do the same as Victor here. Are we differently sure we can’t set the Account ID as part of this? Otherwise great article!

I was able to get this working using the SOAP API. Not as clean as the solution above, but it starts an Automation in the Child BU. I did have to create an API User that had the Default Business Unit to the Child Business Unit. Platform.Load(‘core’, ‘1’); var username = ‘api_user_name (set default BU to child BU)’; var password = ‘api_user_password’; var payload = ”; var endpoint = “”; //Automation Customer Key var customerKey = “17148d1e-872e-6d85-b073-149b9e13a2b1”; var result; var logDE = DataExtension.Init(“Triggered_Automation_Log”); startAutomation(); function startAutomation() { payload += ”; payload += ”; payload += ‘ ‘; payload += ‘… Read more »

Doh, the XML got stripped out. Try this:

Ricardo den Haan

I always try to avoid using the “Platform.Function” syntax at is less readeable than using directly the corresponding API:

Platform.Load('core', '1');
var myAutomation = "Automation_Dummy";

// Search for an automation
var filter = {Property:"CustomerKey",SimpleOperator:"equals",Value:myAutomation};
var automationObject = Program.Retrieve(filter);

// Start automation if "ready"
if (2 == automationObject[0].Status) {
var automationPerformed = Program.Init(myAutomation);