verified
Retrieve all AutomationsLearn how to retrieve all Automations in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include the WSProxy method.
WSProxy
var api = new Script.Util.WSProxy();
var result = [],
moreData = true,
reqID = data = null;
var cols = [
"Name",
"Description",
"CustomerKey",
"IsActive",
"CreatedDate",
"ModifiedDate",
"Status",
"ProgramID",
"CategoryID",
"LastRunTime",
"ScheduledTime",
"LastSaveDate",
"ModifiedBy",
"LastSavedBy",
"CreatedBy",
"AutomationType",
"RecurrenceID"
];
var filter = {
Property: 'Status',
SimpleOperator: 'IN',
Value: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
};
var opts = {
BatchSize: 300
};
var props = {
QueryAllAccounts: false
};
while (moreData) {
moreData = false;
if(reqID) props.ContinueRequest = reqID;
var data = api.retrieve("Automation", cols, filter, opts, props);
if (data != null) {
moreData = data.HasMoreRows;
reqID = data.RequestID;
for (var i = 0; i < data.Results.length; i++) {
result.push(data.Results[i]);
}
}
}
<script runat="server">
Platform.Load("Core","1");
var api = new Script.Util.WSProxy();
try {
var automations = retrieveAllAutomations();
Write(Stringify(automations));
} catch(err) {
Write(Stringify(err));
}
function retrieveAllAutomations() {
var out = [],
moreData = true,
reqID = data = null;
var cols = [
"Name",
"Description",
"CustomerKey",
"IsActive",
"CreatedDate",
"ModifiedDate",
"Status",
"ProgramID",
"CategoryID",
"LastRunTime",
"ScheduledTime",
"LastSaveDate",
"ModifiedBy",
"LastSavedBy",
"CreatedBy",
"AutomationType",
"RecurrenceID"
];
var filter = {
Property: 'Status',
SimpleOperator: 'IN',
Value: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
};
var opts = {
BatchSize: 300
};
var props = {
QueryAllAccounts: false
};
while (moreData) {
moreData = false;
if(reqID) props.ContinueRequest = reqID;
var data = api.retrieve("Automation", cols, filter, opts, props);
if (data) {
moreData = data.HasMoreRows;
reqID = data.RequestID;
for (var i = 0; i < data.Results.length; i++) {
out.push(data.Results[i]);
}
}
}
return out;
}
</script>
[
{
"Schedule": null,
"AutomationTasks": null,
"IsActive": true,
"AutomationSource": null,
"Status": 1,
"Notifications": null,
"ScheduledTime": "0001-01-01T00:00:00.000",
"AutomationType": "scheduled",
"UpdateModified": false,
"LastRunInstanceID": null,
"CreatedBy": 12345678,
"CategoryID": "12345",
"LastRunTime": "0001-01-01T00:00:00.000",
"LastSaveDate": "2018-10-09T04:32:59.952",
"ModifiedBy": 12345678,
"RecurrenceID": "00000000-0000-0000-0000-000000000000",
"LastSavedBy": 12345678,
"InteractionObjectID": null,
"Name": "MyAutomation",
"Description": null,
"Keyword": null,
"Client": null,
"PartnerKey": null,
"PartnerProperties": null,
"CreatedDate": "2018-10-09T04:32:59.920",
"ModifiedDate": "2018-10-09T04:33:00.030",
"ID": 0,
"ObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Owner": null,
"CorrelationID": null,
"ObjectState": null,
"IsPlatformObject": false
},
{
"Schedule": null,
"AutomationTasks": null,
"IsActive": true,
"AutomationSource": null,
"Status": 1,
"Notifications": null,
"ScheduledTime": "0001-01-01T00:00:00.000",
"AutomationType": "scheduled",
"UpdateModified": false,
"LastRunInstanceID": null,
"CreatedBy": 12345678,
"CategoryID": "12345",
"LastRunTime": "0001-01-01T00:00:00.000",
"LastSaveDate": "2018-12-04T05:29:34.070",
"ModifiedBy": 12345678,
"RecurrenceID": "00000000-0000-0000-0000-000000000000",
"LastSavedBy": 12345678,
"InteractionObjectID": null,
"Name": "MyAutomation 2",
"Description": null,
"Keyword": null,
"Client": null,
"PartnerKey": null,
"PartnerProperties": null,
"CreatedDate": "2018-12-04T05:29:33.973",
"ModifiedDate": "2018-12-04T05:29:34.070",
"ID": 0,
"ObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Owner": null,
"CorrelationID": null,
"ObjectState": null,
"IsPlatformObject": false
},
{
"Schedule": null,
"AutomationTasks": null,
"IsActive": true,
"AutomationSource": null,
"Status": 8,
"Notifications": null,
"ScheduledTime": "0001-01-01T00:00:00.000",
"AutomationType": "triggered",
"UpdateModified": false,
"LastRunInstanceID": null,
"CreatedBy": 12345678,
"CategoryID": "12345",
"LastRunTime": "0001-01-01T00:00:00.000",
"LastSaveDate": "2022-02-15T03:50:25.896",
"ModifiedBy": 12345678,
"RecurrenceID": "00000000-0000-0000-0000-000000000000",
"LastSavedBy": 12345678,
"InteractionObjectID": null,
"Name": "MyAutomation 3",
"Description": "",
"Keyword": null,
"Client": null,
"PartnerKey": null,
"PartnerProperties": null,
"CreatedDate": "2022-01-19T03:33:50.849",
"ModifiedDate": "2022-02-15T03:50:26.220",
"ID": 0,
"ObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
"Owner": null,
"CorrelationID": null,
"ObjectState": null,
"IsPlatformObject": false
}
]
Reference
Ressources and references related to the current methods.
Official documentation
SOAP object