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>