1

I have a scenario where I want to block an entire send when a specific flag is "True" and insert an error message into custom error log Data Extension. Basic logic flow is,

IF (errorFlag) THEN
  InsertDE("DE External Key", "ErrorColumnName", "Error Message")
  raiseError("Error Message", false)
ENDIF

The problem I am facing here is,

  • I am using raiseError that blocks the entire send if the custom errorflag is true ( RaiseError("error message“), false)). As per ampscript documentation, insertDE function will not execute if raiseError that blocks the entire send is used, because insert operations are processed only when the send is completed.
  • Tried using last argument of raiseError funtion which preserves the insert operation before raising the error, but that is not working when block entire send option is used.
  • InsertData function will not work in email send. So that option is also not available.
  • Tried calling a separate content block when error flag condition is met and performing insertion using SSJS then come back to the previous content block and execute the raiseError. Even that is failing.

Is there any way we can insert the error message to DE using any possible method and then call raiseError() to block the entire send?

3
  • Why do you have to use RaiseError inside the message? Can you not check your errorFlag condition pre-send via SQL, log your error and include only subscribers where the errorFlag wasn't true in the sendout target group / cancel the send process using a count in a verification activity? In my book RaiseError should be used for last-ditch exception handling, what you describe sounds like a controllable, expected scenario and could simply be handled before send time. This should also improve send processing speed as the system has to do less stuff per subscriber when rendering. Feb 11, 2022 at 11:42
  • @JonasLamberty the errorFlag is not related to subscribers so we cannot check it pre-send via SQL. in actual scenario the condition is basically "IF _messagecontext == "SEND" AND isEmailDraft == "True" THEN". where isEmailDraft is a cutom variable to check the state of email. if isEmailDraft is true I want to block the email.
    – Ajith S
    Feb 11, 2022 at 12:01
  • can you explain how isEmailDraft is defined? If it's anything stored in a data extension, then you can check that with SQL, no? Or where do you read this from? Feb 11, 2022 at 12:35

1 Answer 1

2

EDITED TO USE UPSERT INSTEAD

I have found if you put a conditional based on a variable set to the return of the insert, it will still run that insert inside the Email. As a note, this seems to work with InsertDE only for some, so for a more universal approach, I will change this to UpsertDE instead, which guarantees a return. As this approach will do an insert or an update, it should easily be a replacement for InsertDE.

See below for example:

%%[
  SET @error = 1

  IF _messagecontext == "SEND" THEN
    IF @error == 1 THEN
      SET @upsert = UpsertDE("errorLog",3,"Email",emailname_, "Job",jobid,"Subscriber",_subscriberkey,"Error",Now())
      IF NOT EMPTY(@upsert) THEN
        RaiseError("Errored",false,"Error",500,1)
      ENDIF
    ENDIF
  ENDIF
]%%

By having the RaiseError dependent on the value of the variable @upsert which is the return of the UpsertDE function, you force the RaiseError to process AFTER the Insert, Upsert, Update, etc. are done. Which means those will process prior (and with the setting allowing those to be included) will be processed even if the RaiseError skips the send.

9
  • Thanks for the suggestion, Much Appreciate. But I have tried this and this will not work because of 2 reasons. 1. InsertDE function doesn't have any output value : ampscript.guide/insertde 2. Even though we are forcing the raiseError to execute based on a flag (though insertDE doesn't return anything, we can use other flags), SFMC seems to be holding the insertion in some kind of buffer untill the send is completed or more precisely to see if there is any raiseError call that blocks the send. the above snippet will work in cloud page but not when context is send.
    – Ajith S
    Feb 12, 2022 at 12:10
  • @ajiths - thanks but I ran it in an email and it worked and your argument is incomplete. worst case is change it to upsert instead and then wham an output if you have issue with insertde. As to 2, that is wrong. It will run after as I said due to it being dependent on that data. As said, I tested and ran no problem. Feb 13, 2022 at 12:26
  • I have tried your approach with insertDE once again to confirm. Unfortunately this doesnt work. First of all insertDE function doesnt return any value and you are setting that to a variable. So, all the time it will hold empty/null. Then you are checking if the variable is not empty or not and if not empty call raise error function, which will never happen because your @insert variable is always empty. So the data will be entered into the DE but email send will never be blocked. Not sure how its working for you. But thanks anyway for the suggestions.
    – Ajith S
    Feb 14, 2022 at 8:31
  • Just shift to UpsertDE instead. That gives a return for sure and will insert as well as update - meeting your needs. I will update my answer to use Upsert instead to remove any confusion. Feb 14, 2022 at 16:37
  • Thank you so much for following up on this problem. As I understand from AmpScript, DE functions are described. insertData, UpdateData, UpsertData these functions returns the number of rows affected by the operation, but only works in a landing page, microsite page or CloudPage, or in an SMS message in MobileConnect. whereas below functions will work in email but doesnt return any value. insertDE, updateDE, upsertDE So, we have decided to take this issue with Salesforce Architects. I will update it once we have a solid solution.
    – Ajith S
    Feb 14, 2022 at 20:52

You must log in to answer this question.

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