1

I am using this AMPscript in a Landing Page, and it seems to prevent the page from displaying anything

    %%[

    SET @SubscriberKey = QUERYPARAMETER('SubscriberKey')
    SET @Operation = 'Unsubscribe'

    ]%%

/*HTML*/

    %%[
    IF @Operation == 'Unsubscribe' THEN

UPSERTDATA('Master Leads',1,'SubscriberKey',@SubscriberKey,'Optin',false)


    DELETEDATA('Newsletter Leads','SubscriberKey',@SubscriberKey)

    ]%%

/*HTML*/

    %%[ENDIF]%%

And as soon as i remove the two functions, the page works.

Am I missing something here ? Thanks for your help

6
  • I'd add an IF-THEN to ensure both parameters have a value before the upsert and delete. Looks like you're missing an ENDIF also. Sep 21, 2018 at 14:28
  • I just forgot to add the ENDIF in the post. i added IF-THEN but it's not working. Could it be the spaces in the Data Extension Name ?
    – Zak Ben
    Sep 21, 2018 at 14:38
  • If you could revise your question with the updated code, that'd be helpful. Sep 21, 2018 at 15:01
  • I have updated the question, thanks for you help Adam
    – Zak Ben
    Sep 21, 2018 at 15:20
  • 2
    What error are you receiving on this? Sep 21, 2018 at 16:00

2 Answers 2

4

I recently faced a very similar issue. It turned out that the UpsertData function was trying to create a row without providing a value of a required variable. To avoid this, one needs to make sure that all the non-nullable variables are passed in the function call.

This might not be a general answer to the posted question (Eliot Harper's answer is better in that sense), but it does provide one (possibly non-obvious) thing to check for.

1

Firstly, there's nothing wrong with your code syntax, although I would encourage you to declare your variables with the VAR keyword (as doing so adds the variables to an internal dictionary).

There are a number of different reasons why the page would be returning an error (in your case, you would be seeing a generic 500 error). In some instances, you are able to 'catch' errors by wrapping the AMPscript block with an SSJS try/catch handler, but it won't work in your scenario (I've tried).

However, you can debug your code in Email Studio by making the following changes:

  1. Set the @SubscriberKey value as a constant (for an existing Subscriber Key)
  2. Change UPSERTDATA and UPSERTDATA to UPSERTDE and UPSERTDE (emails use a different function, but have the same arguments)
  3. Paste the code into a new email
  4. Preview the email.

When you preview the email, OMM should return some helpful errors explaining what the problem is (for example, the DE does not exist).

You can also test this without updating the function names (in step 2) and an error will still be returned, but you may need still to update the function names depending on the type of error.

Here's some sample modified code.

%%[
VAR @SubscriberKey, @Operation

SET @SubscriberKey = '1234'
SET @Operation = 'Unsubscribe'

]%%

/*HTML*/

%%[
IF @Operation == 'Unsubscribe' THEN

UPSERTDATA('Master Leads',1,'SubscriberKey',@SubscriberKey,'Optin',false)

DELETEDATA('Newsletter Leads','SubscriberKey',@SubscriberKey)

]%%

/*HTML*/

%%[ENDIF]%%

You must log in to answer this question.

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