0

I'm trying to use DELETEDATA function in AMPscript in unsubscribe process in order to remove record from 2 places ( Data Extensions) AMPscript code is not working when adding this part:

SET @TCX_LOCAL = CONCAT("TCX_",@OOCampaignCode,"_LOCAL") DELETEDATA(@TCX_LOCAL,'SubscriberKey',@SubscriberKey,'Locale',@OOLocale,'CampaignCode',@OOCampaignCode)

Can anyone knows what is wrong with this 2 lines? I'm not able to use DELETEDATA function twice?

I will highly appreciate any advice.

here is my code:

%%[
IF @Operation == 'OptedOut' THEN
SET @OptInStatus = 'OptedOut' 
SET @OptOutDate = NOW() UpdateData('T_MSubscribers',1,'SubscriberKey',@SubscriberKey,'OptInStatus',@OptInStatus,'OptOutDate',@OptOutDate) 
SET @rows = LookupRows('T_MSubscribers','SubscriberKey',@SubscriberKey) 
SET @rowCount = rowcount(@rows) 
IF @rowCount > 0 then 
for @i = 1 to @rowCount do 
SET @row = row(@rows,@i) 
SET @OOCampaignCode = field(@row,'CampaignCode') 
SET @OOLocale = field(@row,'Locale') 
SET @T_NSubscribersDE = CONCAT("TCX_",@OOCampaignCode,"_NewsletterSubscribers")
DELETEDATA(@T_NSubscribersDE,'SubscriberKey',@SubscriberKey,'Locale',@OOLocale,'CampaignCode',@OOCampaignCode) 
SET @T_LOCAL = CONCAT("T_",@OOCampaignCode,"_LOCAL")
DELETEDATA(@T_LOCAL,'SubscriberKey',@SubscriberKey,'Locale',@OOLocale,'CampaignCode',@OOCampaignCode) 
next @i
ENDIF 
]%% 

1 Answer 1

1

The best way to understand such scripts is by introducing error logs or raise errors.

I am inserting one in your existing script to check if the function is even working the way it is intended to assuming that the remaining things like variables like @SubscriberKey, @OOCampaignCode, and @OOLocale are properly set and contain the expected values.

%%[
IF @Operation == 'OptedOut' THEN
    SET @OptInStatus = 'OptedOut' 
    SET @OptOutDate = NOW() 
    UpdateData('T_MSubscribers', 1, 'SubscriberKey', @SubscriberKey, 'OptInStatus', @OptInStatus, 'OptOutDate', @OptOutDate) 

    SET @rows = LookupRows('T_MSubscribers', 'SubscriberKey', @SubscriberKey) 
    SET @rowCount = rowcount(@rows) 

    IF @rowCount > 0 THEN 
        FOR @i = 1 TO @rowCount DO 
            SET @row = row(@rows, @i) 
            SET @OOCampaignCode = field(@row, 'CampaignCode') 
            SET @OOLocale = field(@row, 'Locale') 

            SET @T_NSubscribersDE = CONCAT("TCX_", @OOCampaignCode, "_NewsletterSubscribers")
            SET @deleteResult = DELETEDATA(@T_NSubscribersDE, 'SubscriberKey', @SubscriberKey, 'Locale', @OOLocale, 'CampaignCode', @OOCampaignCode)
            IF @deleteResult != 1 THEN
                RaiseError('Delete failed for T_NSubscribersDE', 1)
            ENDIF

            SET @T_LOCAL = CONCAT("T_", @OOCampaignCode, "_LOCAL")
            SET @deleteResult = DELETEDATA(@T_LOCAL, 'SubscriberKey', @SubscriberKey, 'Locale', @OOLocale, 'CampaignCode', @OOCampaignCode)
            IF @deleteResult != 1 THEN
                RaiseError('Delete failed for T_LOCAL', 1)
            ENDIF

        NEXT @i
    ENDIF 
ENDIF 
]%%

What happens now is this script will now throw an error and halt execution if the DELETEDATA function fails to delete records from either of the two Data Extensions.

2
  • Thank you! I will check that :)
    – Natalia
    Commented Jan 18 at 7:44
  • unfortunately I have all the time the same error: "500 - Internal server error."
    – Natalia
    Commented Jan 18 at 15:24

You must log in to answer this question.

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