0

We are using multiple HTML blocks in a cloudpage (using new contentbuilder while creating cloudpage) and in each HTML block we are fetching titles , statements , image urls from Data extension ( one data extension for each html block )

So my question is if we use try and catch block (as per this discussion - Only execute Data Extension AMPscript functions if the Data Extension exists) to check if that particular DE is exist or not or if someone deletes the DE by accidently then there should not be any bad user experience

so is that fine if we performed this solution for each HTML block - Data extension ? so in our case there are 5 HTML blocks and 5 DEs so is that fine we use try ..catch block in each ? or it will impact any performance issue ?

1
  • To @gortonington's point, a single try/catch would preform better. Since it reduces the number of times you are switching between ampscript and ssjs. Sep 17 at 13:48
3

So, any time you close a script block and open a new one, that will reduce performance. Combine that with a mix of scripting languages (SSJS and AMPscript) and you add more processing. So yes, this will have some impact in total performance and speed of delivery. Try catch itself as well can add a slight delay as well due to how it is executed.

Now the question comes in to how much will it affect it? So, Each one of the above mentions on performance is usually measured in milliseconds, so the answer on how much of an impact it will have is depending mostly on the total number of the above (or similar) performance holes and the speed of the connection for your user.

What I might explore is removing the mixing of languages and utilize just SSJS to do all your actions. SSJS is the preferred language anyway for CloudPages due to all the added functionality and capabilities it offers. Plus try/catch is native to that, reducing the number of script blocks you need to open/close.

Also, I would look to do something like this to validate instead of the method shown in the examples you shared. This is a more performant way to accomplish this as it limits impact by having the lookuprows you need done inside the try/catch and shared out along with the true value or it returns false.

<script runat=server>
//globally setting vars so they are passed out of try/catch context
var badDE, badDeExist, de, deExist;

//DE 1  
try {  
  badDE = Platform.Function.LookupRows('CustomerData','SubscriberKey','acruz@example.com');
  badDeExist = true;
} catch(e) {
  bdayDeExist = false;
}

//DE 2
try {
  de = Platform.Function.LookupRows('gg_de1','SubscriberKey','MySubKey');
  deExist = true;
} catch(e) {
  var deExist = false;
}

</script>

You can then use the return from lookup or the 'exist' var to adjust to if DE exists in the rest of your SSJS. To push to AMPscript, use Platform.Variable.SetValue("@badDeExist",badDeExist); for everything you want to pass.

1
  • 1
    Thank you @Gortonington it worked ........Platform.Variable.SetValue("@badDeExist",badDeExist); - double quotes are not required in 2nd parameter :)
    – Jay
    Sep 21 at 9:26

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.