Skip to content

Instantly share code, notes, and snippets.

@katydorjee
Created February 8, 2019 12:34
Show Gist options
  • Save katydorjee/c7d3bb9045d3d9cba15bb234e800d630 to your computer and use it in GitHub Desktop.
Save katydorjee/c7d3bb9045d3d9cba15bb234e800d630 to your computer and use it in GitHub Desktop.
Run automation from parent Other BU
<script runat="server">
Platform.Load("Core","1.1.1");
var output = "";
var automationCustomerKey = "xxxxxx-xxxx-xxxx-xxxx-xxxxxx";
var buMID = "00000000000000";
var cid = Platform.Function.CreateObject("ClientID");
Platform.Function.SetObjectProperty(cid, "ID", buMID);
Platform.Function.SetObjectProperty(cid, "IDSpecified", "true")
var rr = Platform.Function.CreateObject("RetrieveRequest");
Platform.Function.AddObjectArrayItem(rr, "ClientIDs", cid);
Platform.Function.SetObjectProperty(rr, "ObjectType", "Program");
Platform.Function.AddObjectArrayItem(rr, "Properties", "Name");
Platform.Function.AddObjectArrayItem(rr, "Properties", "ObjectID");
Platform.Function.AddObjectArrayItem(rr, "Properties", "Status");
var sfp = Platform.Function.CreateObject("SimpleFilterPart");
Platform.Function.SetObjectProperty(sfp, "Property", "CustomerKey");
Platform.Function.SetObjectProperty(sfp, "SimpleOperator", "equals");
Platform.Function.AddObjectArrayItem(sfp, "Value", automationCustomerKey);
Platform.Function.SetObjectProperty(rr, "Filter", sfp);
var retrieveStatus = [0,0,0];
var automationResultSet = Platform.Function.InvokeRetrieve(rr, retrieveStatus);
var ObjectID = automationResultSet[0]["ObjectID"];
var Status = automationResultSet[0]["Status"];
if (ObjectID != "null") {
output += "<br>" + automationCustomerKey + " ObjectID : " + ObjectID;
output += "<br>" + automationCustomerKey + " Status: " + Status;
if (Status == 2) {
var obj = Platform.Function.CreateObject("Automation");
Platform.Function.SetObjectProperty(obj, "ObjectID", ObjectID);
Platform.Function.SetObjectProperty(obj, "Client", cid);
var po = Platform.Function.CreateObject("PerformOptions");
var performResult = [0,0,0];
var performStatus = Platform.Function.InvokePerform(obj, "start", performResult, po);
output += "<br><br>performResult: " + Stringify(performResult);
}
/*
Code Status
-1 Error
0 BuildingError
1 Building
2 Ready
3 Running
4 Paused
5 Stopped
6 Scheduled
7 Awaiting Trigger
8 InactiveTrigger
*/
} else {
output += "<br>" + automationCustomerKey + " not found";
}
output += "<br><br>cid: " + Stringify(cid);
Write("<br>" + output);
</script>
@katydorjee
Copy link
Author

Refer for WSProxy code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment