0

I am trying to insert new email address and Zipcode in my DE which doesnt already exist. . I am using lookuprows() on emailaddress field, but while publishing I am getting "500 - Internal server error" . I even try to put my ampscript code within 2 server-side Javascript tags but still getting same error. I am enclosing my whole code below. Please go through it and help me.

<script runat="server">
Platform.Load("Core","1.1.1");
try{
</script>

%%[
Set @EmailAddress = RequestParameter("email_address")
Set @Zipcode = RequestParameter("zip_code")
Set @Lname = "LNU"
set @Fname = "FNU"
SET @Lookup = LookupRows("Amp_NewsletterSignup","EmailAddress", @EmailAddress)
set @rowCount = RowCount(@Lookup)
]%%

%%[
IF ROWCOUNT(@Lookup) == 0 THEN 

   InsertData("Amp_NewsletterSignup","EmailAddrerss", @EmailAddress,"Zipcode", @Zipcode)
   ]%%

<p style="color:red"> You are successfully registered with us </p>
     
%%[Else]%%

   <p style="color:red"> Oops! Entered Email Address is already registered with us </p>

    %%[ENDIF]%%
  
 <script runat="server">
  }catch (e) {
          Write("<b>Error Message:</b> " + Stringify(e.message) + "<br><br><b>Description:</b> " + Stringify(e.description));
  }
</script>
4
  • How do you test this? Are you passing any parameters for email_address and zip_code? Your ampscript looks fine and should work (given you do pass those parameters and that the data extensions you use do exist)
    – zuzannamj
    Jun 11, 2021 at 16:21
  • This is just a processing page coding. I have created one more Landing page which has HTML code for Newsletter signup.
    – Divya
    Jun 11, 2021 at 16:26
  • Do you test this end-to-end?
    – zuzannamj
    Jun 11, 2021 at 16:27
  • Yes, I am testing End- to- End
    – Divya
    Jun 11, 2021 at 16:30

1 Answer 1

0

Your ampscript looks fine and should work (given you do pass those parameters and that the data extensions you use do exist). What you can do to troubleshoot, is add an additional conditional statement to handle a situation where no parameters are passed:

<script runat="server">
Platform.Load("Core","1.1.1");
try{
</script>
<p style="color:red"> 
%%[
Set @EmailAddress = RequestParameter("email_address")
Set @Zipcode = RequestParameter("zip_code")
Set @Lname = "LNU"
set @Fname = "FNU"

IF NOT EMPTY(@EmailAddress) AND NOT EMPTY(@Zipcode) THEN 

SET @Lookup = LookupRows("Amp_NewsletterSignup","EmailAddress", @EmailAddress)
set @rowCount = RowCount(@Lookup)

IF @rowCount == 0 THEN 

InsertData("Amp_NewsletterSignup","EmailAddrerss", @EmailAddress,"Zipcode", @Zipcode,"FirstName",@Fname,"LastName",@Lname)
   ]%%

You are successfully registered with us
     
%%[Else]%%
Oops! Entered Email Address is already registered with us

%%[ENDIF]%%
 
 %%[ELSE]%% 

 Missing parameters.

 %%[ENDIF]%%
</p>
 <script runat="server">
  }catch (e) {
          Write("<b>Error Message:</b> " + Stringify(e.message) + "<br><br><b>Description:</b> " + Stringify(e.description));
  }
</script>
6
  • @Asmita can you please try with the above code and let me know what it says?
    – zuzannamj
    Jun 11, 2021 at 16:35
  • thanks for updating my code, but unfortunately it is still showing same error.
    – Divya
    Jun 11, 2021 at 16:40
  • OK, what are the settings of the Amp_NewsletterSignup data extension? maybe you are trying to insert a row without all required fields? Maybe there's a data mismatch?
    – zuzannamj
    Jun 11, 2021 at 16:43
  • DE has 4 fields EmailAddrerss datatype emailaddress and primary key, Zipcode: datatype Text, FirstName datatype Text, LastName datatype Text. Non of these are NULL
    – Divya
    Jun 11, 2021 at 16:48
  • 1
    Null or nullable? If they are not nullable, then you need to pass all of them in the InsertData function. I have updated my answer to reflect this.
    – zuzannamj
    Jun 11, 2021 at 20:44

You must log in to answer this question.

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