0

I am using the below SSJS WSproxy code to extract the automation details like name, status,start time etc. to create a dashboard

<script runat="server">

Platform.Load("Core","1");

  var prox = new Script.Util.WSProxy();

  var cols = ["Name","Status","StartTime","AutomationID"];

  var filter1 = {
      Property:"Name",
      SimpleOperator:"EQUALS",
      Value: "My_Test_Automation"
  };
  var res = prox.retrieve("AutomationInstance",cols,filter1);

  if (res.Results.length > 0) {
      
      var statusObj = {
  "-1":"Error",
  "0":"BuildingError",
  "1":"Building",
  "2":"Ready",
  "3":"Running",
  "4":"Paused",
  "5":"Stopped",
  "6":"Scheduled",
  "7":"Awaiting Trigger",
  "8":"InactiveTrigger"
}
      
      
      Write('<table align="center" border="1" cellpadding="5" ><tr><th colspan="3">Automation Dashboard</th></tr>')
      for (var i = 0; i < res.Results.length; i++) {
          var autoName = res.Results[i].Name;
          var autoStatusNum = res.Results[i].Status;
          var autoStatus = statusObj[autoStatusNum];
          var StartTime = res.Results[i].StartTime;
           var ID = res.Results[i].AutomationID;
        
          
          Write('<tr><td>' + autoName + '</td><td>' + autoStatus + '</td></tr>'+'<tr><td>' + StartTime+'<tr><td>' + ID)
      }
      Write('</table>')
  }

</script>

I am referring the SFMC documentation to extract the properties of AutomationInstance object - https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/automationinstance.html

I am facing following issues -

  1. I can fetch a single automation details right now as I am using a filter but I would like to extract all automation available in the BU. Please can anyone let me know how I can do this by modifying the filter or the code?
  2. I am able to get values for all the properties but for AutomationID it returns null. Please can someone point out what I am doing wrong here?

1 Answer 1

2

Welcome!

If you want to extract all automations available in BU, then you can use Status / IN filter to have all the possibilities. Also when you change "AutomationID" in cols with "ProgramID" it's going to pop up.

<script runat="server">

  Platform.Load("Core","1");

  var prox = new Script.Util.WSProxy();

  var cols = ["Name","Status","StartTime","ProgramID"];

  var filter1 = {
      Property:"Status",
      SimpleOperator:"IN",
      Value: [-1,0,1,2,3,4,5,6,7,8]
  };
  var res = prox.retrieve("Automation",cols,filter1);

  if (res.Results.length > 0) {
      
      var statusObj = {
  "-1":"Error",
  "0":"BuildingError",
  "1":"Building",
  "2":"Ready",
  "3":"Running",
  "4":"Paused",
  "5":"Stopped",
  "6":"Scheduled",
  "7":"Awaiting Trigger",
  "8":"InactiveTrigger"
}
      
      
      Write('<table align="center" border="1" cellpadding="5" ><tr><th colspan="3">Automation Dashboard</th></tr>')
      for (var i = 0; i < res.Results.length; i++) {
          var autoName = res.Results[i].Name;
          var autoStatusNum = res.Results[i].Status;
          var autoStatus = statusObj[autoStatusNum];
          var StartTime = res.Results[i].StartTime;
           var ID = res.Results[i].ObjectID;
        
          
          Write('<tr><td>' + autoName + '</td><td>' + autoStatus + '</td></tr>'+'<tr><td>' + StartTime +'<tr><td>' + ID)
      }
      Write('</table>')
  }

</script>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .