0

I have a file drop automation which runs everyday around 10:00am. In the background an ETL process runs where it gets the file from another system and process to FTP. Sometimes If the file is received late in ETL It wont be sent out to marketing cloud. Is there a way to get a notification if automation is not run before E.G 11AM just like how we get a notification hen something errors

1

You could create a new Automation and schedule it to run at 11AM daily.

Inside the automation make a script activity that points to the Automation REST endpoint and look at the 'lastRunTime' field. Then have the script send an email if the date is not from today.

Automation Endpoint: GET https://{{yoursubdomain}}.rest.marketingcloudapis.com /automation/v1/automations/{{automationObjectID}}
(This is undocumented, so is 'use at your own risk')

returns JSON like below:

{
    "id": "xxxxxxxx-275d-450a-be60-xxxxxxxxx",
    "name": "myAuto",
    "description": "",
    "key": "myAuto",
    "typeId": 1,
    "type": "scheduled",
    "statusId": 2,
    "status": "Ready",
    "categoryId": 12345,
    "lastRunTime": "2019-09-29T10:46:00.587",
    "lastRunInstanceId": "xxxxxxxxxx-187e-4dba-a6d3-xxxxxxxxxx",
    "schedule": {
        "scheduleStatus": "none"
    },
    "steps": [
                    ......
    ]
}

You can also use the SOAP API endpoint if you don't have the objectID around:

example SOAP envelope:

  <RetrieveRequest>
        <ObjectType>Automation</ObjectType>
        <Properties>Name</Properties>
        <Properties>LastRunTime</Properties>
        <Filter xsi:type="SimpleFilterPart">
            <Property>Name</Property>
            <SimpleOperator>equals</SimpleOperator>
            <Value>{{myAutoName}}</Value>
        </Filter>
     </RetrieveRequest>

or in WSProxy:

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

  var cols = ["Name","LastRunTime"];
  var filter = {
      Property: "Name",
      SimpleOperator: "equals",
      Value: {{myAutoName}}
  };
  var res = prox.retrieve("Automation", cols, filter);

A quick sample script: (This assumes you already have a TriggeredSendDefinition created and ready to be sent to.)

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

var autoProperty = "CustomerKey" //Property for retrieve
var simpleOperator = "equals"    //SimplerOperator for retrieve
var autoValue = 'myAutoKey';     //Value for retrieve

var autoResults = retrieveAuto(autoProperty,simpleOperator,autoValue);

var autoLastRun = new date(autoResults.Results[0].LastRunTime);

var today = new date(GetDate());

var endTime = today.setHours(11,0,0,0);
var startTime = today.setHours(0,0,0,0);

if (autoLastRun > startTime && autoLastRun < endTime) {
  Write("Success");
} else {
  Write("Failed to run");
  var customerKey = "trigger_test_gg";
  var alertResults = sendAlertTrigger(customerKey);
}

function retrieveAuto(autoProperty, simpleOperator, autoValue) {
  var prox = new Script.Util.WSProxy();

  var cols = ['*'];
  var filter = {
  Property: autoProperty,
  SimpleOperator: simpleOperator,
  Value: autoValue
  };
  var res = prox.retrieve("Automation", cols, filter);

  return res;
}

function sendAlertTrigger(customerKey) {
  var prox = new Script.Util.WSProxy();

  //I set this to include 2 subscribers in the call, but can add more or less as needed
  var ts= {
    TriggeredSendDefinition: {CustomerKey: customerKey}
    ,Subscribers: [ 
      {
          EmailAddress: 'email1@myDomain.com'
        , SubscriberKey: 'email1@myDomain.com'
        , Attributes: [
            {
             Name: 'Automation',
             Value: 'myAutomationName'
           },
           {
             Name: 'Date',
             Value: GetDate()
           }
        ]
      },
      {
          EmailAddress: 'email2@myDomain.com'
        , SubscriberKey: 'email2@myDomain.com'
        , Attributes: [
            {
             Name: 'Automation',
             Value: 'myAutomationName'
           },
           {
             Name: 'Date',
             Value: GetDate()
           }
        ]
      }
    ]

  };

  var res = prox.createItem("TriggeredSend", ts);

  return res;
}

</script>
| improve this answer | |
  • @ gortonington Thanks, That's a great insight ! what would be the script like ? – Rajukanum Oct 14 '19 at 21:05
  • @kaushik - apologies for the late reply, but I have edited and now added a sample script for this request to my answer. – Gortonington Oct 19 '19 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.