1

I have a scenario where we want to send the same email from multiple business units every day. The email should get updated daily, but I wanted to have a check in the automations in each business unit to make sure that the email had been updated in the past 24 hours, and stop the automation if it has not. I got the SSJS working just fine, it grabs the email and checks the modified date. I can see the logic working in a Cloud Page, and I've moved it over to a Script.

I thought it would be as simple as "throw"ing a javascript error, which I thought would/should stop the automation, but it doesn't, the automation shows that the script ran successfully, even though when I run the same logic in a Cloud Page it causes a 500 when the email has not been updated (as expected). I also tried returning false from within the script, but it still shows in Automation Studio that the script is executing successfully.

So, my question is; how do I get the automation to see that my script has failed, or more specifically, how can I get the automation to fail from within a script?

Update:

Here's my code (with the suggestions from the answers provided by this post):

<script language="JavaScript" runat="Server">
Platform.Load("core","1");

var myEmail = Email.Init("TargetEmail");
//results = Email.Retrieve({Property:"ID",SimpleOperator:"equals",Value:"57929"}); // Old
results = Email.Retrieve({Property:"ID",SimpleOperator:"equals",Value:"708337"}); // New

for (var index in results) {
  var email = results[index];
  var modifiedDate = new Date(email.ModifiedDate);
  var now = Now();
  var secondsInADay = 60*60*24;
  var secondsSinceUpdated = (now - modifiedDate) / 1000;
  if (secondsSinceUpdated > secondsInADay) {
    var rows = Platform.Function.DeleteData('Verification Data Extension',['Updated'],['True']);
  } else {
    var rows = Platform.Function.InsertData('Verification Data Extension',['Updated'],['True']);
  }
}
</script>

This code is working great now!

0

As per your situation I believe there are different ways of setting up the validations. And I believe this is the safest method that I'd go with as it uses the default automation studio Verification Activity.

This is how I would set up:

Step 1: I would create a log DE that has a text field and maybe let's call it SSJSError.

Step 2: Within your SSJS you'd have two SSJS functions wrapped in your if and else statements

  • add a row with a static value of true when the modified date within the email is true.

  • remove the row in the DE when modified date isn't true.

For example:

<script language="JavaScript" runat="Server">
Platform.Load("Core","1.1");

//Please change the comparison operator to check the email modified date below
if (1 == 1) {
    var rowAdd = Platform.Function.InsertData('SSJS_Error_Log',['SSJSError'],['True']);
}
else{
    var rowDelete = Platform.Function.DeleteData('SSJS_Error_Log',['SSJSError'],['True']);
}
</script>

Step 3: After your SSJS activity within the automation you'd have a verification activity that would stop the automation if the record count on that DE is zero and also send you an email notification. enter image description here

  • This works fine in my CloudPage, so thanks for the pointer. The problem I'm running into now is that the exact same code does not seem to work in my Script, either when I run it manually or as part of an automation. I'm not sure how to get visibility into why the Script isn't working. – Mark Ransom Jun 22 '18 at 22:42
  • Can you please post your code for the clarity of the issue? Also the code above was tested in automation and it has worked. – Brad Sapkota Jun 24 '18 at 23:56
  • Added my code sample as part of the original post. – Mark Ransom Jun 25 '18 at 14:39
  • Could you mention the <script language="JavaScript" runat="Server"> up at the top of your script...seems like you're missing to declare the script. – Brad Sapkota Jun 26 '18 at 6:40
  • That was my problem, I thought that the <script> tag was only necessary when running a script in a context of an email or cloud page. Lesson learned. The solution you outlined is working great, thanks! – Mark Ransom Jun 26 '18 at 14:50
0

I am sure there is a way to do this via the script, but a solution outside of that would be to do the following:

  1. Create a DE with 1 field - Success
  2. Have your SSJS update this DE with a Yes or some other value if your requirements have been met
  3. put in a 'Verification interaction' that checks if this DE is 0 and to stop the automation if it is.
  4. insert your other interactions
  5. run a SQL query that removes the previous entry into the Success DE. Something like SELECT JobId FROM [_Sent] WHERE 1=2 with the action set to 'OVERWRITE' and target SuccessDE.
    • This will return 0 results, deleting all from your SuccessDE. Feel free to replace _Sent with another DE in your account to increase processing speed.

This should allow you to stop the automation if the SSJS return does not meet your criteria.

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.