Below is the code which I tried, but when the automation is erroring out the status is populating as paused, scheduled, stopped. The error status is not population.
Code:
<style>
body, a, input, td, th {font-family:sans-serif; font-size:12px;}
</style>
<script runat="server">
Platform.Load("core","1");
var debug = false;
try {
var prox = new Script.Util.WSProxy();
var mids = [XXX,YYY]; //eight mid values
if (debug) {
Write("<br>mids: " + Stringify(mids));
}
Write("<table border='1'>");
Write("<tr>");
Write("<th>MID</th>");
Write("<th>Automation Names</th>");
Write("<th>BU Names</th>");
Write("<th>Status</th>");
Write("<th>NextScheduleTime</th>");
Write("</tr>");
for (i = 0; i < mids.length; i++) {
var mid = mids[i];
prox.setClientId({"ID": mid});
var obj = "Automation";
var cols = ["ProgramID","CustomerKey","Status","Name","ScheduledTime"];
// The only supported operators for the Automation object are: IN, EQUALS. Complex filter is not supported.
// https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/automation.htm
var filter = {
Property: "Status"
, SimpleOperator: "IN"
, Value: [-1,2,5,3,6,7]
};
var opts = null;
var props = null;
var moreObjs = true;
var reqID = null;
while (moreObjs) {
moreObjs = false;
var objs = reqID == null ? prox.retrieve(obj, cols, filter, opts, props) : prox.getNextBatch(obj, reqID);
if (objs != null) {
moreObjs = objs.HasMoreRows;
reqID = objs.RequestID;
for (var j = 0; j < objs.Results.length; j++) {
var automationObj = objs.Results[j];
var statusDsc = "";
var buDsc = "";
switch (automationObj.Status) {
case -1: statusDsc = "Error";
if(mid==XXX)
buDsc="Production";
else
buDsc="Developement";
break;
case 3: statusDsc = "Running";
if(mid==XXX)
buDsc="Production";
else
buDsc="Developement";
break;
case 6: statusDsc = "Scheduled";
if(mid==XXX)
buDsc="Production";
else
buDsc="Developement";
break;
case 2: statusDsc = "Ready";
if(mid==XXX)
buDsc="Production";
else
buDsc="Developement";
break;
case 5: statusDsc = "Stopped";
if(mid==XXX)
buDsc="Production";
else
buDsc="Developement";
break;
case 7: statusDsc = "Awaiting Trigger";
if(mid==XXX)
buDsc="Production";
else
buDsc="Developement";
break;
}
Write("<tr>");
Write("<td>" + mid + "</td>");
Write("<td>" + automationObj.Name + "</td>");
Write("<td>" + buDsc + "</td>");
Write("<td>" + statusDsc + "</td>");
if(statusDsc == "Stopped" || statusDsc == "Ready" || statusDsc == "Scheduled" || statusDsc == "Error" || statusDsc == "Running")
{
schTime=automationObj.ScheduledTime;
Write("<td>" + schTime + "</td>");
}
Write("</tr>");
}
}
}
prox.resetClientIds();
}
Write("</table>");
} catch (e) {
if (debug) {
Platform.Response.Write("<br><br>e: " + Stringify(e));
}
}
</script>