0

In Salesforce Marketing Cloud, I'm trying to determine a way to stop or pause an automation if it's run within a certain amount of time. Essentially, there's a Marketing Cloud bug where a single file of ours causes the automation to run twice. So while I can stop the automation if the data extension meets certain requirements, I don't know of a way to stop an automation based on previous runs. Does anyone know of a way to build a query or some automation studio functionality that addresses this?

2 Answers 2

1

What you can do is create a separate DE, a filter definition, a filter activity, a validation step, and a query.

DE:
This will hold the run time of your Automation.

Fields:

AutoID  |  RunDateTime
pkey    |     pkey    

AutoID = Your unique id for your automation (can be whatever you wanna name it)
RunDateTime - The date/time that your automation ran

Filter Definition
This will filter against your DE, looking to see if there is a value within X date/time range.

You would want to create a filter like so (assuming 1 hr is schedule):
RunDateTime is greater then Today minus 1 hour

Filter Activity
This is basically turning the filter definition into an interaction that can be added into an automation. The end result will be a filtered DE.

Query This will add in the automation info to the DE you created. Sample:

Select TOP 1 'myAuto1' as AutoID,
GetDate() as RunDateTime
FROM [myDE]

Validation Step
Inside the Automation you would have a step that looks to see if there is any records inside your new DE. IF so, then stop the auto. If not then continue on.

You then put the pieces together into automation like so:

Step 1: FilterActivity
Step 2: Validation
Step 3: Query to add time of run to DE
Step 4: (your normal step 1)
...

This will then make your automation skip if run again within the defined time inside your filter definition.

0

I like @Gortonington answer.

Here is an alternative solution if you want to check the automation every X minutes:

  • Create an automation to run a
  • Script activity which checks for your automation

The following script activity can be used to check if an automation is running. If so, you can wait X minutes and try to run again or if the automation still runs after N minutes, you can stop it.

    <script runat="server">
    Platform.Load("Core","1.1.1");

    var automationKey   = 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
    var maxTries        = 12; // 12 * 5 minutes = 1 hour max wait time
    var sleepTime       = 300000; // 5 minutes
    var hasRun          = false;
    var prox            = new Script.Util.WSProxy();
    var cols            = [ "ProgramID", "CustomerKey", "CustomerKey", "Name", "Status" ];
    var filter          = { Property: "CustomerKey", SimpleOperator: "equals", Value: automationKey };

    try {

        for (var i = 1; i<maxTries; i++) {

            var rr              = prox.retrieve("Automation", cols, filter);
            var objectID        = rr.Results[0].ObjectID;
            var status          = rr.Results[0].Status;
            var automationName  = rr.Results[0].Name;

            if (rr != null) {
                if (status == 2) {
                    var rr = prox.performItem("Automation", { ObjectID: objectID }, "Start", {});
                    hasRun = true;

                    /* DO ANY ACTION AFTER RUN */

                    break;
                } 

                // go to sleep and try again X minutes if automation is already running
                if (status == 3) {
                    sleep(sleepTime);
                }
                if (status == -1 || status == 0 || status == 4 || status == 5 || status == 6 ) {
                    logError(automationName,automationKey,'Error','Automation failed with status code: ' + status + ' and ObjectId: ' + ObjectId);
                }
            } 
            else {
                logError(automationName,automationKey,'Error','Automation not found');
            }

        }

        // if it has not run after maxTries * sleepTime we log an error
        if( hasRun == false ){
            /* STOP THE AUTOMATION? */
            logError(automationName,automationKey,'Error','Automation is still running after '+(sleepTime/1000/60)*maxTries+' minutes');
        }

    } catch (e) {
        logError(automationName,automationKey,'Error','Automation failed: ' + Stringify(e));
    }


    function sleep(m) {
        var start = new Date().getTime();
        for (var i = 0; i < 1e7; i++) {
            if ((new Date().getTime() - start) > m) {
                break;
            }
        }
    }


    function logError(automationName,automationKey,type,message) {
        var logDE = DataExtension.Init("ERROR LOG DE");
        logDE.Rows.Add({
            "Timestamp": new Date().getTime()/1000|0,
            "Date SYD":Platform.Function.SystemDateToLocalDate(Now()),
            "Automation Name":automationName,
            "Automation Key":automationKey,
            "Type":type,
            "Message":message
        });
    }

</script>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .