2

I need to skip sending an email based on the evaluation of a condition that I'm defining in an AMPscript block in my email, and also make a POST request to a an HTTP endpoint.

Here's what I have:

<script runat=server language=ampscript>

var @response, @result

set @result='fail' /* hardcoded for example purpose */

if @result=='fail' then

   HTTPPost('http://requestb.in/1km46cl1',
          'text/xml',
          Concat('result failed for subscriber ',_subscriberkey),
          @response
          )

   RaiseError("Email skipped", true)

endif 
</script>

This works fine; if I generate a Preview for a Subscriber, then if @result=='fail' evaluates to true, the POST request is made and I see the RaiseError message.

However, when I use this email in a Triggered Send, the email is moved to the Error queue (which I would expect), but the POST request is not made. It's almost as if OMM evaluates the AMPscript for any RaiseError() function and aborts sending the email (instead of parsing it from top to bottom). Does anyone know of a solution?

5

I'd remove the RaiseError() function altogether and put the rest of the AMPScript in a separate Content Area that outputs @result.

For example:

<script runat=server language=ampscript>

var @response, @result

set @result = 'fail' /* hardcoded for example purpose */

if @result == 'fail' then
  HTTPPost('http://requestb.in/1km46cl1',
         'text/xml',
         Concat('result failed for subscriber ',_subscriberkey),
         @response
         )
endif 
</script>%%=v(@result)=%%

Then in the Exclusion Script field in your Triggered Send Definition, you can check the value of @result:

TreatAsContent(ContentAreaByName("my contents\path\to\content-area"))=="fail"

When the email is triggered, the Content Area will be evaluated (along with the HTTP POST request). The subscriber email will be skipped since the Exclusion Script evaluates @result=='fail' to true.

If you don't see the Exclusion Script input box, SFMC support can enable it for you.

Reference

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.