I have seen many people interested in keeping tabs on their Automations all in a single place. This usually involves at least the Automation Name and current status.
There are also quite a few other items that can be grabbed as well inside the ‘Automation’ Object and pulled in to your Dashboard.
First thing you will need to do is to grab a list of all the automations in your account. Now, this takes a minute to figure out as the Automation Object requires an ‘equals’ or ‘in’ filter for it to return values.
Luckily, you can just use all of the statuses in an ‘In’ and it will return all the automations. See below for a screenshot of all the Status codes and their meanings:
Below is a sample raw SOAP envelope requesting all the automations in an account using the above Status ‘trick’.
<RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI"> <RetrieveRequest> <ObjectType>Automation</ObjectType> <Properties>Name</Properties> <Properties>Status</Properties> <Filter xsi:type="SimpleFilterPart"> <Property>Status</Property> <SimpleOperator>IN</SimpleOperator> <Value>-1</Value> <Value>0</Value> <Value>1</Value> <Value>2</Value> <Value>3</Value> <Value>4</Value> <Value>5</Value> <Value>6</Value> <Value>7</Value> <Value>8</Value> </Filter> </RetrieveRequest> </RetrieveRequestMsg>
This will return the results in an array that you then parse out and can then iterate out via a For loop in a display.
Example Response:
<RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI"> <OverallStatus>OK</OverallStatus> <RequestID>XXXXXXXXXXXXXXXXXXXXX</RequestID> <Results xsi:type="Automation"> <PartnerKey xsi:nil="true" /> <ObjectID xsi:nil="true" /> <Name>Automation1</Name> <Status>2</Status> </Results> <Results xsi:type="Automation"> <PartnerKey xsi:nil="true" /> <ObjectID xsi:nil="true" /> <Name>Automation2</Name> <Status>2</Status> </Results> </RetrieveResponseMsg>
If you want to make the calls via a Cloudpage instead of externally, you can simplify the whole thing by using WSProxy to do it, doing a call like below:
<script runat="server"> Platform.Load("Core","1.1.1"); var prox = new Script.Util.WSProxy(); var cols = ["Name","Status"]; var filter = { Property: "Status", SimpleOperator: "IN", Value: [-1,0,1,2,3,4,5,6,7,8] }; var res = prox.retrieve("Automation", cols, filter); </script>
From there you just iterate through the response and create the dashboard:
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="2">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]; Write('<tr><td>' + autoName + '</td><td>' + autoStatus + '</td></tr>') } Write('</table>') }
This will then output a table that contains all of your automations and the code description of their current status.
The purpose of statusObj
is to take the number returned from WSProxy call and make it something more easily understood when displayed. This is handled via the autoStatus
var setting.
Completed script would look like:
<script runat="server"> Platform.Load("Core","1.1.1"); var prox = new Script.Util.WSProxy(); var cols = ["Name","Status"]; var filter = { Property: "Status", SimpleOperator: "IN", Value: [-1,0,1,2,3,4,5,6,7,8] }; var res = prox.retrieve("Automation", cols, filter); 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="2">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]; Write('<tr><td>' + autoName + '</td><td>' + autoStatus + '</td></tr>') } Write('</table>') } </script>
**Added 06/29/2020** As many people have mentioned, the ‘Status’ in the above is not the current run status, but more of a ‘scheduled’ status. The best way to get the last run status via WSProxy/SOAP is to hit the AutomationInstance Object.
As the ‘AutomationInstance’ Object that is documented in the official docs, really is pretty terrible at working like it is documented and using the ‘*’ wildcard leads to a huge envelope that can greatly slow down the process, I usually steer people to the ‘ProgramInstance’ object.
But, after finding a hidden gem in the official documents showing how to utilize the AutomationInstance object to gather the status of the last run of the Automation (which, goes against pretty much everything documented on the Object)!
Do note, that if you run a Describe request on this object, literally every property returned has IsRetrievable as false, and some of the properties shown in the linked sample (e.g. ProgramID, etc.) are not even present on the describe. Something is very off about those Automation Objects…
Below is a Sample SOAP envelope:
<RetrieveRequest> <ObjectType>AutomationInstance</ObjectType> <Properties>Status</Properties> <Filter xsi:type="SimpleFilterPart"> <Property>ProgramInstanceID</Property> <SimpleOperator>equals</SimpleOperator> <Value>308e3e81-e1b7-4d3b-8072-4403eb103618</Value> </Filter> </RetrieveRequest>
You then just grab the ‘StatusMessage’ value from the Response and you now have your ‘last run’ status!
This should translate into WSProxy fairly easily. Below is just a sample, I have not verified it inside of SFMC yet though.
<script runat="server"> var prox = new Script.Util.WSProxy(); var cols = ["Status"]; var filter = { Property: "ProgramInstanceID", SimpleOperator: "equals", Value: "XXXXXXXXXXXXX" }; var res = prox.retrieve("AutomationInstance", cols, filter);
Great article! I’m trying this right now and it works – but is it possible to filter this somehow? I’d like to only show certain statuses, like -1,1,5 for example.
In the meantime I’ll try to make the table fit our dashboards’ theme ;)! Thanks again!
You can do that by adjusting the WSProxy filter to only include your statuses. For example: [-1,0,1,2,3,4,5,6,7,8] in the JS filter variable, would become [-1,1,5] instead and would only return automations with those statuses.
This does not give the current status. For example if the automation failed today , still the status says Scheduled. I used the AutomationInstance object to get the current statuses but could not filter on the current date. Any suggestions?
I know AutomationInstance SOAP Object is, for lack of a better term, “Wonky” right now, so I would use the legacy “ProgramInstance” SOAP Object. You can likely Adjust it to filter on ‘ProgramID equals XXXXXX’ and if you add the option for BatchSize and limit it to 1, you will only receive the most recent run. The value you are looking for is under the Property ‘StatusMessage’. I am going to add in a sample SOAP envelope for this into the post for easy reference.
Thanks for the reply , I tried the below code and it seems like the AutomationInstance returns the records in ordered list, the latest run is the last record in the array.
So this code works:
var res = prox.retrieve(“AutomationInstance”, cols, filter);
var stat = res.Results[res.Results-1].StatusMessage;
var statcode = res.Results[res.Results-1].Status;
var name = res.Results[res.Results-1].Name;
var lastupdated = res.Results[res.Results-1].StatusLastUpdate;
You can try this and confirm.
I can do one even better. Apparently there is a SOAP envelope in the docs that works for lastruninstance. I have no idea why this one works and most other attempts does not, but if you grab the ‘LastRunInstanceID’ from the automation call, you can then plug that into AutomationInstance and get the status, etc. I will update my post again with this information. Thank you for all your efforts to help make my content as relevant and up to date as possible!
Greta article! I am going to try this today. Is there any way though to retrieve the history of start and finish times for each automation for the past X days?
Hi @Gortonington! This is a great article, thank you for it. I would like to try it and retrieve all Automations + Statuses from all our business units. What would be your approach/recommendation of doing it?
a) Creating 1 CloudPage in the Parent Account which requests AccessToken for each childBU (do I need to request it?) and show the automations+statuses for each BUs?
In which part of the script should the MID be inserted in order to achieve this?
Or..
b) Creating a CloudPage on each BU and then having a master CloudPage which tabs/links to each of them to access all of them from 1 page?
These are just couple of ideas I had, but maybe you have even a better recommendation?
Thank you in advance and also for your incredible useful SFMC articles! #loveThemAll
Cheers
In general, I would recommend A – but honestly, it really depends on the context around it to definitively make a recommendation.