Skip to content

Instantly share code, notes, and snippets.

@MamaiRachid
Last active April 4, 2022 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MamaiRachid/6b147663a64a092d25717ba015dd6b84 to your computer and use it in GitHub Desktop.
Save MamaiRachid/6b147663a64a092d25717ba015dd6b84 to your computer and use it in GitHub Desktop.
/* Function to retrieve automation status */
function getAutomationStatus(automationName) {
var result = api.retrieve("Automation", ["Name","ProgramID","CustomerKey","Status"], {
Property: "Name",
SimpleOperator: "equals",
Value: automationName
});
var automation = result.Results[0];
var objectId = automation.ObjectID;
if(objectId == null) throw "No automation with the name \"" + automationName + "\" was found.";
else {
var status = getAutomationStatusName(automation.Status);
if(status == "Running" || status == "Ready") {
var response = "Active";
}
else var response = status;
}
return status;
}
/* Function to retrieve automation status based on returned status code - Thanks Ivan ;) */
function getAutomationStatusName(num) {
switch(num) {
case -1:
status = 'Error';
break;
case 0:
status = 'Building error';
break;
case 1:
status = 'Building';
break;
case 2:
status = 'Ready';
break;
case 3:
status = 'Running';
break;
case 4:
status = 'Paused';
break;
case 5:
status = 'Stopped';
break;
case 6:
status = 'Scheduled';
break;
case 7:
status = 'Awaiting trigger';
break;
case 8:
status = 'Inactive trigger';
break;
}
return status;
}
@ivanrazine
Copy link

you're welcome ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment