0

When any Email Campaign is send from the Marketing cloud, I want to check the latest Subscriber Consent for Email_Optin from the Master_lead DE which is Sync with CRM.

If the Email_Optin is not true then it should raise the error and save the details in 'RaiseError_SendLog_DE' DE.

Below code throws an error when I am trying to Preview Email but when I actual send the email it is cancelled and is not deployed.

/** Consent OptIn**/
set @RaiseError_Flag = 'False'
set @JobID = JobID
set @ListID = ListID
set @BatchID = _JobSubscriberBatchID
set @SubID = Id

set @Error_DE = 'RaiseError_SendLog_DE'
set @Master_Lead = 'Webinar_test'
set @numRowsToReturn = 0

set @Crows = LookupOrderedRows(@Master_Lead,@numRowsToReturn,'Id', 'Id', @SubID)
set @Crowcount = rowcount(@Crows)

IF @Crowcount == 0 THEN
   set @RaiseError_Flag = 'True'
   set @SL_MiscData = CONCAT(@SL_MiscData, 'No Optin Status')
ELSE
  set @MCEmailOptIn__c = Field(Row(@Crows,1),'MCEmailOptIn__c')
     IF @MCEmailOptIn__c != 'True' THEN
         set @RaiseError_Flag = 'True'
         set @SL_MiscData = CONCAT(@SL_MiscData, 'status=', Trim(@Optin_Status))
         
    ENDIF
ENDIF


IF @RaiseError_Flag == 'True' THEN
   set @SL_MiscData = SUBSTRING(CONCAT('Consent Raise Error!', @SL_MiscData), 1, 150)
   
   InsertDE(@Error_DE, 'JobID', @JobID, 'ListID', @ListID, 'BatchID', @BatchID, 'SubID', @SubID, 'SL_Subscriber_key', @SL_Subscriber_key, 'SL_MiscData', @SL_MiscData, 'ErrorCode', @ErrorCode, 'SL_Email_Address', @SL_Email_Address, 'Created_Date', @Created_Date,)
   
   RaiseError("Do not Send to subscriber - Consent not available or true", True)
   
ENDIF
1
  • I would not recommend this approach for suppressing subscribers in a send. Inserts in emails are batched until the end of a send. Plus, you still get charged for a send if you skip it via raiseError. Sep 30 at 19:47
0

I'd recommend creating an Exclusion Script content block in Content Builder and adding your logic to that, then in your email's send definition, add an AMPscript conditional that returns true or false.

There are multiple examples floating around on how to do that. Here's one.

Perhaps you can update your question to clarify the need for creating a log for subscribers that are skipped.

0

Using the Above script I'm able to raise an error and save the error values in DE:

/** Consent OptIn Start **/
set @RaiseError_Flag = 'False'
set @JobID = JobID
set @ListID = ListID
set @BatchID = _JobSubscriberBatchID
set @SubID = Id

set @Error_DE = 'RaiseError_SendLog_DE'
set @Master_Lead_Data = 'Webinar_test'
set @numRowsToReturn = 0

set @Crows = LookupOrderedRows(@Master_Lead_Data,@numRowsToReturn,'Id', 'ID', @SubID)
set @Crowcount = rowcount(@Crows)

IF @Crowcount == 0 THEN
   set @RaiseError_Flag = 'True'
   set @SL_MiscData = CONCAT(@SL_MiscData, 'No Optin Status')
ELSE
  set @MCEmailOptIn__c = Field(Row(@Crows,1),'MCEmailOptIn__c')
     IF @MCEmailOptIn__c != 'True' THEN
         set @RaiseError_Flag = 'True'
         set @SL_MiscData = CONCAT(@SL_MiscData, 'status=', Trim(@MCEmailOptIn__c))
         
    ENDIF
ENDIF

IF @RaiseError_Flag == 'True' THEN
   set @SL_MiscData = SUBSTRING(CONCAT('Consent Raise Error!', @SL_MiscData), 1, 150)
   InsertDE(@Error_DE,"SL_Subscriber_key",@SubID,"JobID",@JobID,"SL_MiscData",@SL_MiscData,"SL_Email_Name", emailname_)
   
   RaiseError("Do not Send to subscriber - Consent not available or true", true, "Email Failed Validation", "7000", 1)
   
ENDIF
/** Consent OptIn End **/

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.