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?


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

<script language="JavaScript" runat="Server">

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']);

This code is working great now!

2 Answers 2


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">

//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']);
    var rowDelete = Platform.Function.DeleteData('SSJS_Error_Log',['SSJSError'],['True']);

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. Jun 22, 2018 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. Jun 24, 2018 at 23:56
  • Added my code sample as part of the original post. Jun 25, 2018 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. Jun 26, 2018 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! Jun 26, 2018 at 14:50

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.

  • This seems somewhat error-prone because around 4-5% of the time because the individual activity steps can hang and fail on their own. If the SQL activity never triggered in this case due to SF server error; the overwrite would never happen, meaning that you'd be looking at a success from a previous run rather than the current one.
    – JordanGS
    May 20, 2022 at 20:27
  • @JordanGS As stated in the answer from 4 years ago, I started it saying there is likely a better way. SFMC always has risk on everything. It is all about finding the right risk and building with failure in mind. May 21, 2022 at 1:19

You must log in to answer this question.

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