Retrieve an Automation verified

Learn how to retrieve an Automation in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include Platform and WSProxy methods.

Platform

var name = "MyAutomation";

var cols = [
    "Name",
    "Description",
    "CustomerKey",
    "IsActive",
    "CreatedDate",
    "ModifiedDate",
    "Status",
    "ProgramID",
    "CategoryID",
    "LastRunTime",
    "ScheduledTime",
    "LastSaveDate",
    "ModifiedBy",
    "LastSavedBy",
    "CreatedBy",
    "AutomationType",
    "RecurrenceID"
];

var request = Platform.Function.CreateObject("RetrieveRequest");

for(var i = 0; i < cols.length; i++) {
    Platform.Function.AddObjectArrayItem(request, "Properties", cols[i]);
}

Platform.Function.SetObjectProperty(request, "ObjectType", "Automation");

var filter =  Platform.Function.CreateObject("SimpleFilterPart");

Platform.Function.SetObjectProperty(filter, "Property", "Name");
Platform.Function.SetObjectProperty(filter, "SimpleOperator", "equals");
Platform.Function.AddObjectArrayItem(filter, "Value", name);

Platform.Function.SetObjectProperty(request, "Filter", filter);

var status = [0, 0, 0];

var result = Platform.Function.InvokeRetrieve(request, status);
<script runat="server">

    Platform.Load("core", "1");

	try {

        var name = "MyAutomation";

        var cols = [
            "Name",
            "Description",
            "CustomerKey",
            "IsActive",
            "CreatedDate",
            "ModifiedDate",
            "Status",
            "ProgramID",
            "CategoryID",
            "LastRunTime",
            "ScheduledTime",
            "LastSaveDate",
            "ModifiedBy",
            "LastSavedBy",
            "CreatedBy",
            "AutomationType",
            "RecurrenceID"
        ];

        var request = Platform.Function.CreateObject("RetrieveRequest");

        for(var i = 0; i < cols.length; i++) {
            Platform.Function.AddObjectArrayItem(request, "Properties", cols[i]);
        }

        Platform.Function.SetObjectProperty(request, "ObjectType", "Automation");

        var filter =  Platform.Function.CreateObject("SimpleFilterPart");

        Platform.Function.SetObjectProperty(filter, "Property", "Name");
        Platform.Function.SetObjectProperty(filter, "SimpleOperator", "equals");
        Platform.Function.AddObjectArrayItem(filter, "Value", name);

        Platform.Function.SetObjectProperty(request, "Filter", filter);

        var status = [0, 0, 0];

        var result = Platform.Function.InvokeRetrieve(request, status);

        Platform.Response.Write(Platform.Function.Stringify(result));
		
	} catch(error) {

        Platform.Response.Write(Platform.Function.Stringify(error));

    }	

</script>
[
    {
        "Schedule": null,
        "AutomationTasks": null,
        "IsActive": true,
        "IsActiveSpecified": true,
        "AutomationSource": null,
        "Status": 2,
        "StatusSpecified": true,
        "Notifications": null,
        "ScheduledTime": "0001-01-01T00:00:00.000",
        "ScheduledTimeSpecified": false,
        "AutomationType": "scheduled",
        "UpdateModified": false,
        "UpdateModifiedSpecified": false,
        "LastRunInstanceID": null,
        "CreatedBy": 0,
        "CreatedBySpecified": true,
        "CategoryID": "12345",
        "LastRunTime": "0001-01-01T00:00:00.000",
        "LastRunTimeSpecified": false,
        "LastSaveDate": "2022-12-13T12:04:44.313",
        "LastSaveDateSpecified": true,
        "ModifiedBy": 0,
        "ModifiedBySpecified": true,
        "RecurrenceID": "00000000-0000-0000-0000-000000000000",
        "LastSavedBy": 715074318,
        "LastSavedBySpecified": true,
        "InteractionObjectID": null,
        "Name": "MyAutomation",
        "Description": "",
        "Keyword": null,
        "Client": null,
        "PartnerKey": null,
        "PartnerProperties": null,
        "CreatedDate": "2022-12-13T10:16:59.390",
        "CreatedDateSpecified": true,
        "ModifiedDate": "2022-12-13T12:04:44.527",
        "ModifiedDateSpecified": true,
        "ID": 0,
        "IDSpecified": false,
        "ObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        "Owner": null,
        "CorrelationID": null,
        "ObjectState": null,
        "IsPlatformObject": false,
        "IsPlatformObjectSpecified": false
    }
]

WSProxy

var api = new Script.Util.WSProxy();

var name = "MyAutomation";

var cols = [
    "Name",
    "Description",
    "CustomerKey",
    "IsActive",
    "CreatedDate",
    "ModifiedDate",
    "Status",
    "ProgramID",
    "CategoryID",
    "LastRunTime",
    "ScheduledTime",
    "LastSaveDate",
    "ModifiedBy",
    "LastSavedBy",
    "CreatedBy",
    "AutomationType",
    "RecurrenceID"
];

var result = api.retrieve("Automation", cols, {
    Property: "Name",
    SimpleOperator: "equals",
    Value: name
});
<script runat="server">

    Platform.Load("core", "1");

    var api = new Script.Util.WSProxy();
	
	try {

        var name = "MyAutomation";

        var cols = [
            "Name",
            "Description",
            "CustomerKey",
            "IsActive",
            "CreatedDate",
            "ModifiedDate",
            "Status",
            "ProgramID",
            "CategoryID",
            "LastRunTime",
            "ScheduledTime",
            "LastSaveDate",
            "ModifiedBy",
            "LastSavedBy",
            "CreatedBy",
            "AutomationType",
            "RecurrenceID"
        ];

        var result = api.retrieve("Automation", cols, {
            Property: "Name",
            SimpleOperator: "equals",
            Value: name
        });

        Write(Stringify(result));
		
	} catch(error) {
        Write(Stringify(error));
    }	

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "Schedule": null,
            "AutomationTasks": null,
            "IsActive": true,
            "AutomationSource": null,
            "Status": 2,
            "Notifications": null,
            "ScheduledTime": "0001-01-01T00:00:00.000",
            "AutomationType": "scheduled",
            "UpdateModified": false,
            "LastRunInstanceID": null,
            "CreatedBy": 0,
            "CategoryID": "3267",
            "LastRunTime": "2022-10-25T08:01:49.677",
            "LastSaveDate": "2022-10-25T07:56:39.946",
            "ModifiedBy": -1000,
            "RecurrenceID": "00000000-0000-0000-0000-000000000000",
            "LastSavedBy": 100122390,
            "InteractionObjectID": null,
            "Name": "MyAutomation",
            "Description": "Updated",
            "Keyword": null,
            "Client": null,
            "PartnerKey": null,
            "PartnerProperties": null,
            "CreatedDate": "2022-10-25T07:50:30.197",
            "ModifiedDate": "2022-10-25T08:21:50.663",
            "ID": 0,
            "ObjectID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
            "CustomerKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
            "Owner": null,
            "CorrelationID": null,
            "ObjectState": null,
            "IsPlatformObject": false
        }
    ],
    "HasMoreRows": false
}

Reference

Ressources and references related to the current methods.

Official documentation
SOAP object

Last Updated: