0

I am trying to error Handle my Cloud page in SFMC.

If anything goes wrong in the Ampscript Block, user should be redirected to an error page. There is a success scenario where I redirect the user to Success page within Ampscript.

I have tried using a mix of SSJS and AmpScript. Here is a Sample code. Is there a way of doing a redirect through SSJS directly instead of using a mix of SSJS and AMPScript

Issue with this code is if I comment out the Success Redirection, it works. If I put both redirects, it goes to the catch block every time

<script runat="server" type="text/javascript">
 Platform.Load("core", "1.1.3");
try{
</script>
%%[
/*Do Operations Search Operations on DE.

set @confirmation = Success_URL
Redirect(@Confirmation)

]%% <script runat="server" language="javascript">
 } catch(e) { 
  </script>
 %%[
 set @errorUrl= /*Some URL*/
 Redirect(@errorUrl)

 ]%%
 <script runat="server" language="javascript">
 } 
 </script>
9
  • 2
    Why are you loading core 1.1.3? As far as I know, 1.1.1 is the current release. Commented May 12, 2017 at 11:20
  • Have you spat out anything on the page before the redirect? You can't start writing to the buffer and then redirect. So any HTML/Writes/outputs before the code above might be your issue.
    – Macca
    Commented May 15, 2017 at 14:14
  • Refer to this answer, this might help you.
    – Abhishek
    Commented May 19, 2017 at 5:16
  • @AdamSpriggs - Actually, 1.1.5 is the latest library. Commented May 25, 2017 at 13:01
  • I couldn't find any documentation that mentioned anything past 1.1.1 Commented May 25, 2017 at 13:08

2 Answers 2

0

This is not a problem related to your code but a known SFMC issue. Unfortunately, it won't be fixed.

You need to either do a redirect outside of a try block or leverage a workaround shared by @Gortonington on StackExchange.

1

According to the SSJS documentation, there is a Redirect function available within the core SSJS library.

Here is the example below:

<script runat="server" language="javascript">
Platform.Load("core", "1.1.1");

try {
    //DO SOMETHING and REDIRECT
    Redirect("http://success-page.com",true);
 } 
 catch(e) {
    //REDIRECT TO ERROR PAGE
    Redirect("http://error-page.com",true);
} 
 </script>
1

You must log in to answer this question.

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