Does anyone know a way to determine with ampscript whether a DE exists or not prior to doing a LookupRows()? In my case, the DE I'm looking up may or may not exist. And if it doesn't, I wanted to stop the send for that subscriber and not the entire job. My current code is below. Tips and tricks are much appreciated. Thanks in advance everyone.

IF DataExtensionRowCount("THIS_DE_DOES_NOT_EXIST") > 0 THEN
 SET @TEST = "Good Test, your DE exists do your lookup here"
 RaiseError("Bad Test, your DE does not exist", true)

As per my test, one of the ways you can achieve this is by using SSJS. You will setup your SSJS within an email. If you use the try and catch functions within SSJS and wrap your lookup functions then you can manipulate the errors.

Here is an example:

<script runat="server" language="javascript">
    Platform.Load("core", "1");
    try {
        var CheckDE = DataExtension.Init("DE_Name_TO_Check");
        var CheckDEStatus = CheckDE.Rows.Lookup(["FieldName"],[Value]);
    catch (e) {
        Platform.Function.RaiseError("DE does not exist",true,"statusCode","3");


The try block is running the lookup rows function and checking to see if the rows exists in a specific DE. Since DE doesn't exists the function will error and it will return you to the catch block where you can set your SSJS RaiseError function.

Also the true status in the RaiserError function will only stop the send for a specific subscriber and proceed to next subscriber send.

  • Hi @Brad Sapkota, I like the direction but when I paste your code into my email it gives me an error that says "An error occurred when attempting to execute a Javascript block. See inner exception for detail." rather than it initiating the RaiseError. Any thoughts there?
    – Nolan
    Mar 2 '18 at 0:09
  • Are you using classic content builder or modern content builder? Mar 2 '18 at 0:38
  • Hi Brad, I built this in classic. It's a standard html/paste email.
    – Nolan
    Mar 2 '18 at 14:01
  • 1
    @Nolan The script works perfectly fine, I have test it myself. Just to give you a context, the system shows you error while doing a send preview because this is what RaiseError is doing in back-end. If you try doing a guided send with a script the email send doesn't fail but stops from sending email to the subscribers which is kind of a real way to test this case. Hope this helps. Mar 2 '18 at 23:59
  • Hi Brad, ahh that makes perfect sense. I'll give that a shot and see how it goes. Thanks for all your help, much appreciated.
    – Nolan
    Mar 3 '18 at 0:00

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.