0

I'm having problems on an unsubscribe page when i add an insertDATA function. The page is working well without this function.

SO i try to insert "SubscriberID" (Data type is texte 50 length, and it's the Primary key) and "rm_optin_c" = false (data type is Boolean, nullable is true and default value is "false") into the DE "DE_TAMPON_Unsub_Pref_Page".

The code that makes the Cloudpage error is this one :

Set @optintampon = 'false'
set @insertoptin = insertData("DE_TAMPON_Unsub_Pref_Page", "rm_optin_c", @optintampon, "SubscriberID", @subkey)

The AMP for the entire Cloudpage is

  set @subkey = _subscriberKey
  set @email = AttributeValue("emailaddr")
  set @brandnlspecialoccasion = IIF(RequestParameter("brandnlspecialoccasion")=='on','true','false')
  set @cocktailinspiration = IIF(RequestParameter("cocktailinspiration")=='on','true','false')
  set @distillerynews = IIF(RequestParameter("distillerynews")=='on','true','false')
 
 
 
 
 
  IF (@brandnlspecialoccasion == 'false' AND @cocktailinspiration == 'false' and @distillerynews == 'false') then
  set @version = 'A'
  
  

  
    set @updateRecord = UpdateSingleSalesforceObject(
                             "Contact", @subkey,
                             "Newsletter_subscription_Brand_News_Sp__c", @brandnlspecialoccasion,
                             "NewsletterSubscriptionCocktailInspirat__c", @cocktailinspiration,
                             "Newsletter_subscription_Dystillerie__c", @distillerynews,
                             "rm_OptIn__c","false"
                        );
 
 Set @optintampon = 'false'

set @insertoptin = insertData("DE_TAMPON_Unsub_Pref_Page", "rm_optin_c", @optintampon, "SubscriberID", @subkey)


  else
  set @version = 'B'
   set @updateRecord = UpdateSingleSalesforceObject(
                             "Contact", @subkey,
                             "Newsletter_subscription_Brand_News_Sp__c", @brandnlspecialoccasion,
                             "NewsletterSubscriptionCocktailInspirat__c", @cocktailinspiration,
                             "Newsletter_subscription_Dystillerie__c", @distillerynews                          
                        );
  ENDIF
  
  
 IF RequestParameter("submitted") == true THEN
  set @optinglobal = IIF(RequestParameter("Email_Opt_in")=='on','true','false')
  IF @optinglobal == 'true' THEN
  set @updateRecord2 = UpdateSingleSalesforceObject(
                             "Contact", @subkey,                          
                             "rm_OptIn__c","true"
                        );
                        
                       ENDIF
                       ENDIF

 ]%%

Does anyone know why adding the insertData line makes the whole Page an error 500 ?

6
  • 1
    Could you try wrapping your code into an SSJS try... catch statement? That could potentially return the error. Other than that, does a record for this particular SubscriberID already exist in the DE? You could potentially try changing the function from InsertData to UpsertData to avoid a primary key violation error. Commented Sep 15, 2022 at 6:45
  • I'm not sure, because the problem appears when i try to publish the page, it's instantly in error 500. My problem is not the data i try to put into the DE, but to publish the Cloud Page. The DE is empty so it shouldn't have problem of PK violation. And i already tryed to use UpsertData, but unfortunatly it doesnt change anything. Commented Sep 15, 2022 at 8:20
  • The rm_optin_c is of the Boolean data type in the data extension? Currently you set the value as 'false' which is a string, maybe try one of these: Set @optintampon = false or Set @optintampon = 0 Commented Sep 15, 2022 at 8:24
  • Yes rm_optin_ is Boolean data type in the DE. i tryed to set @optintampon to false or 0 but it still tells me that i cannot publish the cloud page Commented Sep 15, 2022 at 8:40
  • Maybe post a screen of what you seen when you try to publish, but you should be able to save and publish the page regardless of the errors shown in the preview. Can you try to do that? Preview should fail here anyway since it does not have access to any personalization strings like _subscriberkey. Commented Sep 15, 2022 at 8:51

1 Answer 1

2

I suspect this is due to lack of proper data validation prior to firing your insertData() function. It expects a value in @subkey variable. This is set in this statement in the top of your code: set @subkey = _subscriberKey. However, when the Cloud Page is just viewed, and not accessed via CloudPagesUrl() function, _subscriberKey is not available, resulting in @subkey being set to null.

This means, that this CloudPage could theoretically work, when following a link from an email. To prevent the error from occurring, I would recommend you to check whether or not @subkey is actually set to something meaningful:

IF NOT EMPTY(@subkey) THEN
SET @insertoptin = insertData("DE_TAMPON_Unsub_Pref_Page", "rm_optin_c", @optintampon, "SubscriberID", @subkey)
ENDIF

A natural question would be:

But Lukas, I also use @subkey in my UpdateSingleSalesforceObject() function. Why doesn't this fail as well?

Well, UpdateSingleSalesforceObject() simply returns 0 if the update wasn't successful. While insertData() throws an error, in a very non-elegant way.

2
  • Thanks so much Lukas, it worked !! Commented Sep 15, 2022 at 14:08
  • You’re welcome! Commented Sep 15, 2022 at 16:05

You must log in to answer this question.

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