0

I'm trying to write some AMPscript to assign vouchers to all customers for every variation of country and language.

I can make it work for a segment of the customers but not for every variation of language and country even the logic is pretty straightforward, I can't figured out what I'am doing wrong

SubscriberKey is the same as CustomerID

BFBBV-EN-2019 - data extension

Black Friday Voucher – Email Send 6th December

enter image description here

    %%[
      set @BFBBVSubscriber = Lookup("Black Friday Voucher – Email Send 6th December", "SubscriberKey", "SubscriberKey", @CustomerID)

      if (@CustomerID == @BFBBVSubscriber) then

      ]%%

      %%[/* UK targeting */
      if ((@lang=='en' and (@prefcountry==1 or empty(@prefcountry))) or ((@lang=='us' or @lang=='au' or @lang=='nz') and @prefcountry==1)) then 

      set @couponCode = ClaimRowValue("BFBBV-EN-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- UK Content Start -->


           %%=v(@CouponCode)=%%


      <!-- UK Content End -->


      %%[ /* AU targeting */
      elseif ((@lang=='au' and (@prefcountry==27 or empty(@prefcountry))) or ((@lang=='us' or @lang=='en' or @lang=='nz') and @prefcountry==27) or (@prefcountry==29)) then 

      set @couponCode = ClaimRowValue("BFBBV-AU-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%


      <!-- AU Content Start -->


           %%=v(@CouponCode)=%%


      <!-- AU Content End -->


      %%[ /* US targeting */
      elseif ((@lang=='us' and (@prefcountry==18 or empty(@prefcountry))) or ((@lang=='au' or @lang=='en' or @lang=='nz') and @prefcountry==18)) then 

      set @couponCode = ClaimRowValue("BFBBV-US-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- US Content Start -->


           %%=v(@CouponCode)=%%


      <!-- US Content End -->


      %%[ /* NZ targeting */
      elseif ((@lang=='nz' and (@prefcountry==35 or empty(@prefcountry))) or ((@lang=='au' or @lang=='en' or @lang=='us') and @prefcountry==35) or (@prefcountry==38)) then 

      set @couponCode = ClaimRowValue("BFBBV-NZ-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- NZ Content Start -->


           %%=v(@CouponCode)=%%


      <!-- NZ Content End -->


      %%[ /* DE targeting */
      elseif (@lang=='de') then

      set @couponCode = ClaimRowValue("BFBBV-EUR-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- DE Content Start -->


           %%=v(@CouponCode)=%%


      <!-- DE Content End -->


      %%[ /* ES targeting */
      elseif (@lang=='es') then 

      set @couponCode = ClaimRowValue("BFBBV-EUR-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- ES Content Start -->


           %%=v(@CouponCode)=%%


      <!-- ES Content End -->


      %%[ /*FR targeting */
      elseif (@lang=='fr') then 

      set @couponCode = ClaimRowValue("BFBBV-EUR-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- FR Content Start -->


           %%=v(@CouponCode)=%%


      <!-- FR Content End -->


      %%[ /* IT targeting */
      elseif (@lang=='it') then 

      set @couponCode = ClaimRowValue("BFBBV-EUR-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- IT Content Start -->


           %%=v(@CouponCode)=%%


      <!-- IT Content End -->


      %%[ /* JP targeting */
      elseif (@lang=='ja') then 

      set @couponCode = ClaimRowValue("BFBBV-JP-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- JP Content Start -->


           %%=v(@CouponCode)=%%


      <!-- JP Content End -->


      %%[ /* NL targeting */
      elseif (@lang=='nl') then 

      set @couponCode = ClaimRowValue("BFBBV-EUR-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- NL Content Start -->


           %%=v(@CouponCode)=%%


      <!-- NL Content End -->


      %%[ /* RU targeting */
      elseif (@lang=='ru') then 

      set @couponCode = ClaimRowValue("BFBBV-RU-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- RU Content Start -->


           %%=v(@CouponCode)=%%


      <!-- RU Content End -->


      %%[ /* SV targeting */
      elseif (@lang=='sv') then 

      set @couponCode = ClaimRowValue("BFBBV-SV-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- SV Content Start -->


           %%=v(@CouponCode)=%%


      <!-- SV Content End -->


      %%[ /* ZH targeting */
      elseif (@lang=='zh') then 

      set @couponCode = ClaimRowValue("BFBBV-CNY-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- ZH Content Start -->


           %%=v(@CouponCode)=%%


      <!-- ZH Content End -->


      %%[ /* ROW/EN */
      elseif (@CustomerID == @BFBBVSubscriber) then

      set @couponCode = ClaimRowValue("BFBBV-EN-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
      ]%%

      <!-- EN Content Start -->


           %%=v(@CouponCode)=%%


      <!-- EN Content End -->



      %%[endif]%%

      %%[endif]%%
1

I have shortened the script and made some comments.

Maybe this helps you but please leave a comment because i am not totally sure that i covered the aspect you wanted an solution for.

%%[
/* We do not know how you set @prefcountry therefore we do not know if the empty function can be used*/
/* empty function only works reliably when you set the value with AttributeValue() like set @prefcountry = AttributeValue("ColumnName")*/

set @BFBBVSubscriber = Lookup("Black Friday Voucher – Email Send 6th December", "SubscriberKey", "SubscriberKey", @CustomerID)

if (@CustomerID == @BFBBVSubscriber) then   
    /* UK targeting */
    if ((@lang=='en' and (@prefcountry==1 or empty(@prefcountry))) or ((@lang=='us' or @lang=='au' or @lang=='nz') and @prefcountry==1)) then 
        set @couponCode = ClaimRowValue("BFBBV-EN-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
    /* AU targeting */
    elseif ((@lang=='au' and (@prefcountry==27 or empty(@prefcountry))) or ((@lang=='us' or @lang=='en' or @lang=='nz') and @prefcountry==27) or (@prefcountry==29)) then 
        set @couponCode = ClaimRowValue("BFBBV-AU-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
    /* US targeting */
    elseif ((@lang=='us' and (@prefcountry==18 or empty(@prefcountry))) or ((@lang=='au' or @lang=='en' or @lang=='nz') and @prefcountry==18)) then 
        set @couponCode = ClaimRowValue("BFBBV-US-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
    /* NZ targeting */
    elseif ((@lang=='nz' and (@prefcountry==35 or empty(@prefcountry))) or ((@lang=='au' or @lang=='en' or @lang=='us') and @prefcountry==35) or (@prefcountry==38)) then 
        set @couponCode = ClaimRowValue("BFBBV-NZ-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
    /* Europe targeting */
    elseif @lang=='de' or @lang=='es' or @lang=='fr' or @lang=='it' or @lang=='nl' then
        set @couponCode = ClaimRowValue("BFBBV-EUR-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
    elseif (@lang=='ja') then 
        set @couponCode = ClaimRowValue("BFBBV-JP-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
    /* RU targeting */
    elseif (@lang=='ru') then 
        set @couponCode = ClaimRowValue("BFBBV-RU-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
    /* SV targeting */
    elseif (@lang=='sv') then 
         set @couponCode = ClaimRowValue("BFBBV-SV-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
    /* ZH targeting */
    elseif (@lang=='zh') then 
         set @couponCode = ClaimRowValue("BFBBV-CNY-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
    /* ROW/EN */

    /* The following if clause if totally senseless. You can only enter this state when you fullfilled the condition previously, checking it again is redudant*/
    /* elseif (@CustomerID == @BFBBVSubscriber) then*/
    /*    set @couponCode = ClaimRowValue("BFBBV-EN-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)*/
    /* You do not have a ELSE clause which I strongly advice in basicly any (only very few not) scenario, you always have to make sure you thought about every aspect*/
    /* Even when the else statement would be nothing i would still include it */
    else
        set @couponCode = ClaimRowValue("BFBBV-EN-2019","CouponCode","IsClaimed","None Available","SubscriberKey",@CustomerID)
    endif
/* You do not have a ELSE clause which I strongly advice in basicly any (only very few not) scenario, you always have to make sure you thought about every aspect */
/* Even when the else statement would be nothing i would still include it */
else
    /* Seems there shouldn't be done anything, maybe raiserror or sth? */
endif
]%%

%%=v(@couponCode)=%%

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.