Last active
April 4, 2022 14:23
-
-
Save MamaiRachid/6b147663a64a092d25717ba015dd6b84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you're welcome ;)