0

We are trying to fetch Promo Code for each customer and updating the issued promo code status to true in DE. While updating we noticed the update row count is -1, still the DE is getting updated. Because of this we are not able to use new promo codes. Please find below the code sample:

<script runat="server">
Platform.Load("core","1");
var dePromoCodes = DataExtension.Init("PROMO_CODE_TESTDM");
var deAudience = DataExtension.Init("DMTEST_BD_AUD_1");
var audienceFilter = {
                     Property:"is_processed",
                     SimpleOperator:"equals",
                     Value:"N"
                 };
var objSubscribers = deAudience.Rows.Retrieve(audienceFilter);
var intNumSubs = objSubscribers.length;

Write("Count : " + intNumSubs + "</br>");
try{
 for (var intSubCount = 0; intSubCount < intNumSubs; intSubCount++){
  var objSubscriber = objSubscribers[intSubCount]
   var complexfilter = {
                 LeftOperand:{
                     Property:"is_claimed",
                     SimpleOperator:"equals",
                     Value:'false'
                 },
                 LogicalOperator:"AND",
                 RightOperand:{
                     Property:"campaign_code",
                     SimpleOperator:"equals",
                     Value: objSubscriber.campaign_unique_code
         }};

  var coupon_rows = Platform.Function.LookupRows('PROMO_CODE_TESTDM','is_claimed','false');
  Write("coupon_rows count : "+coupon_rows.length+"</br>")
  var coupon_row = coupon_rows[0];
  Write("customer_id : " +intSubCount+" "+ objSubscriber.customer_id+ "</br>");
  Write("Coupon : " +intSubCount+" "+ coupon_row.coupon_id+ "</br>");  
  var updatecount = Platform.Function.UpdateData("PROMO_CODE_TESTDM",["coupon_id"],[coupon_row.coupon_id],["is_claimed"],["true"]);
  Write("updatecount : " +" "+ updatecount.length+ "</br>");   
 }
 Write("Done");
}
catch (ex) {
 Write("An error has occurred: " + Stringify(ex));
}
</script>

1 Answer 1

0

You can use ClaimRowValue function for this kind of issues to make everything easier. It simply assigns the coupon code to a user when the code is executed and changes the value from False to True.

You can check here:

https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/claimrowvalue.htm

Example code:

SET @coupon = ClaimRowValue('PROMO_CODE_TESTDM', 'coupon_id', 'is_processed', 'False', 'customer_id', _subscriberkey)

You must log in to answer this question.

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