I've written a script with WSProxy that retrieves all Automations (Programs) in a Marketing Cloud business unit. Then, I retrieve all runs (AutomationInstance) of that automation and get the status of the last run to check if the Automation errored. Then this gets outputted to the page as an Automation Dashboard.
I found that the 'Status' property of the Automation itself is not accurate enough, it shows no 'Error' status if the last run errored. So for each Program loop, I need to do another WSProxy request that gets the status of the last run, this is pretty taxing on the loadtime of the page.
This is the script:
var prox = new Script.Util.WSProxy();
// Retrieve all automations
var cols = ["Name", "Status", "ModifiedDate", "CustomerKey", "ObjectID"];
var filter = {
Property: "Status",
SimpleOperator: "IN",
Value: [-1,0,1,2,3,4,5,6,7,8]
};
var list = prox.retrieve("Program", cols, filter);
var retrieveAmount = list.Results.length;
// Loop through each automation
for(var i = 0; i < retrieveAmount; i++ ) {
var listItem = list.Results[i];
// Set List item vars
var name = listItem.Name;
var customerKey = listItem.CustomerKey;
var modified = listItem.ModifiedDate;
// Retrieve the runs of the automation in the loop
var prox = new Script.Util.WSProxy();
var cols = ["Status", "CustomerKey"];
var filter = {
Property:"CustomerKey", SimpleOperator:"equals", Value: customerKey
};
var res = prox.retrieve("AutomationInstance", cols, filter);
// Get the last run status
var len = res.Results.length - 1;
var status = Stringify(res.Results[len].Status);
// If the last run didn't error, get the status of the automation
if(status != '-1') {
var status = listItem.Status;
}
// Set variables for output
var statusString = statusString + ';' + status
var modifiedString = modifiedString + ';' + modified
var nameString = nameString + ';' + name
}
My idea was to retrieve only the first 20 automations, and have some sort of selectbox in which a user can select to retrieve more rows. However this requires the first 20 automations to be sorted by 'ModifiedDate' so the most relevant automations get retrieved first. Is there any possibility to sort the rows when you're retrieving them via the WSProxy? Or are there any other ways I can improve the loading time of the page? Thanks