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 retrievable 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

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

newest oldest most voted
Notify of
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);


I am trying this code to retrieve data through automation:

Platform.Load(“Core”,”1.1.1″); var rr = Platform.Function.CreateObject(“RetrieveRequest”); Platform.Function.SetObjectProperty(rr, “ObjectType”, “Automation”); Platform.Function.AddObjectArrayItem(rr, “Properties”, “CustomerKey”); Platform.Function.AddObjectArrayItem(rr, “Properties”, “ObjectID”); Platform.Function.AddObjectArrayItem(rr, “Properties”, “Status”); Write(Stringify(Status));
always status value are coming as null, how to retrieve all the values using automation object?


Hi good article!

Is it possible to create a new automation with ssjs?

I’ve trying but I can not be able to …

How can I create new automations with activities?

Is it possible?

Thank you


Can we use this script to re-start the automation if the status is “skipped”?


Hi Adam,

Thanks for sharing this.
I need to perform exactly the action from your post when clicking on a SUBMIT button in a landing page. However, I do not know SSJS.
Shall I just replace the key with External Key below?
var automationCustomerKey = “CUSTOMERKEY-OF-AUTOMATION”
and use your code as it is?
Could you also help me to understand how this can be performed when clicking on SUBMIT button? Thanks!