0

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

To fetch the status of the automations, you need to retrieve on the Automation Instance Object.

Below is the sample code, which fetches all the automations in all the BUs and checks the status of the automations in last 24 hours.

    //Automation Instance
    function AutomationInstance(CustomerKey,mid,marketName,foldername)
{
          var childreqID = null;
          var childprops = null;
          var childmoreObjs = true;
          prox.setClientId({"ID": mid});
       var AutomationInstance = "AutomationInstance";
          var childcols = ["CustomerKey","Status","StartTime","StatusLastUpdate","Name"];  
                    var childfilter = {
          
                    Property:"CustomerKey",
                    SimpleOperator:"IN",
                    Value:  CustomerKey //Passing more than one automation
                };

      try{
                  
        while (childmoreObjs)
        {
            childmoreObjs = false;
            var childobjs = childreqID == null ? prox.retrieve(AutomationInstance, childcols, childfilter) : prox.getNextBatch(childobjs, childreqID);
          if (childobjs != null) 
            {
             childmoreObjs = childobjs.HasMoreRows;
         childreqID = childobjs.RequestID;
           var resultsStore = [];          
            for (var u = 0; u < childobjs.Results.length;u++)
              {  
                       var automationInsitanceObj = childobjs.Results[u]; 
                       var StartTime = automationInsitanceObj.StartTime;       
                       var customerkey = automationInsitanceObj.CustomerKey;
                       var instancestatus = automationInsitanceObj.Status;  
                       var AutomationName = automationInsitanceObj.Name
                       var today = new Date();
                       var prevDate = new Date();
                       var yesterday = new Date((new Date()).valueOf() - 1000*60*60*24);
                       prevDate.setDate(today.getDate()-1);
     
          if(StartTime >= yesterday && instancestatus == -1)
           {                 
           var rows  = Platform.Function.UpsertData('Automation_Monitoring',['MID','CustomerKey'],[mid,customerkey],['Status','ErrorDate','AutomationName','BusinessUnit','FolderName'],["Error",StartTime,AutomationName,marketName,foldername]);    
           }         
           
         }//end for       
             }//end if
                  }// end while
                }// end try
               
  catch (e) {
      Platform.Response.Write("child object error for" + Stringify(e)); 
  }
       prox.resetClientIds();
     }// end function
  • Thank you @Swathi but i dont want to hardcode the CustomerKey and so i have to create an DE "Automation_Monitoring " to capture the details? – Joey Jan 8 at 13:19
  • Storing the details in a Monitoring DE is optional. But what you need, is to reterive the automation object, fetch all the automations and pass in all the customerkey as an array! – Swati Mishra Jan 8 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.