Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katydorjee/328e086d7ad0dc4fddb4006b6ea7a9ae to your computer and use it in GitHub Desktop.
Save katydorjee/328e086d7ad0dc4fddb4006b6ea7a9ae to your computer and use it in GitHub Desktop.
A script to run an automation in a child BU from another child BU.
/*
##To initiate an automation from one child business unit (BU) to another or from a child BU to a parent BU.
#1. Run the following Script in the parent BU and obtain the ObjectID of the automation in the child BU.
*/
<script runat="server">
Platform.Load("core","1.1.1");
var prox = new Script.Util.WSProxy();
var MID = 10000000000;
prox.setClientId({ "ID": MID });
var cols = ["Name", "ProgramID", "IsActive"];
var filter = {
Property: "Name",
SimpleOperator: "equals",
Value: "<Name of the automation>"
};
var desc = prox.retrieve("Automation", cols, filter);
Write('<br>ObjectID: ' + desc.Results[0].ObjectID);
</script>
/*
#2. Run below script in Child BU.
The script below will run in a child BU to execute an automation in another child BU.
*/
<script runat="server">
Platform.Load("core", "1.1.1");
var automationConfig = {
"AutomationName": "<Name of the automation>",
"AutomationExKey": "<ExternalKey of the automation>",
"AutomationObjectID": "<ObjectID from the above script>",
"BusinessUnit": "XYZ",
"MID": 10000001
}
var prox = new Script.Util.WSProxy();
prox.setClientId({ "ID": automationConfig.MID });
var props = {
ObjectID: automationConfig.AutomationObjectID
};
var action = "start";
var opts = {};
var res = prox.performItem("Automation", props, action, opts);
var status = res.Status;
var statusCode = res.Results[0].StatusCode;
Write("res: " + Stringify(res) + "<br><br>");
Write("statusCode: " + statusCode);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment