SFMC tip #3 – redirect error in try catch block

in  Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks
1 minute read

If you have redirect function inside the try catch block, either as mixture of SSJS with AMPScript or only in SSJS, it will throw an 500 – Internal Server Error.

Let’s take a look on few examples what can create an error that will take you some quality debugging time to figure it out. And frankly to debug something inside the marketing cloud is one of the most depressing things happened to me in a while.

<script runat=server>
try{
  //do somothing
  throw 'This is error'
}catch(e){
	Redirect('https://example.com',true)
}

</script>
<script runat=server>
 try{
 </script>
  %%[
   /* Do some AMPScript */
   /* e.g. */
 	UpdateSingleSalesforceObject('Contact', 'contactId', 'someField', 'True')
    Redirect(CloudPagesURL(1))
 ]%% 
 <script runat=server>
 }catch(e){
  //do something
 }
</script>

Examples above will throw beautiful 500 – Internal Server Error and leave you guessing what is wrong this time.

To make this work you have to move any redirect functions outside the try-catch block.

<script runat=server>
 var error = false
try{
  //do somothing
  throw 'This is error'
}catch(e){
  	/* you can log e.message into  Data Extension */
	error = true
}
Redirect('https://example.com', true)
</script>
in  Marketing Automation, Salesforce Marketing Cloud, SFMC Tips & Tricks

SFMC tip #2 – Column names with suffix _dat, _call, _from fail to validate

less than a minute read

Data extension column names with _dat, _call, _from, _join suffix will fail to validate, due to using old style JOIN The fix is really easy you only need to wrap the column name like [test_from] and the problem with validation is history If you know more suffixes that will throw an error let me know

Continue reading