0

why this code is not working?

<script runat="server" language="JavaScript">
    Platform.Load("Core", "1");
    var couponsDE = DataExtension.Init("9F69D084-64B5-4FAA-ACB4-D6CB5EBA5F02");
    var couponRows = couponsDE.Rows.Retrieve();
    for (let i = 0; i < couponRows.length; i++) {
       if (couponRows[i].Used === "False") {
          var coupon = couponRows[i].CodiceCoupon;
          var remove = couponsDE.Rows.Remove(["CouponCode"], [coupon]);
          var add = couponsDE.Rows.Add({ CouponCode: coupon, Used : "True" });
       }
    }
</script>

if I put this code out of for loop, it works

1 Answer 1

1

I recall I read somewhere that Marketing Cloud supports JavaScript ES5 syntax so you need to use variables defined with var instead of let. I would try this:

<script runat="server" language="JavaScript">
    Platform.Load("Core", "1");
    var couponsDE = DataExtension.Init("9F69D084-64B5-4FAA-ACB4-D6CB5EBA5F02");
    var couponRows = couponsDE.Rows.Retrieve();
    for (var i = 0; i < couponRows.length; i++) {
       if (couponRows[i].Used === "False") {
          var coupon = couponRows[i].CodiceCoupon;
          var remove = couponsDE.Rows.Remove(["CouponCode"], [coupon]);
          var add = couponsDE.Rows.Add({ CouponCode: coupon, Used : "True" });
       }
    }
</script>
2
  • 1
    ES3, not ES5! shocking :p, right ?
    – TaouBen
    Jul 28, 2023 at 11:03
  • @TaouBen Thank you for letting me know. I just read again and it's the same what you said. SSJS, specifically The Core library currently stands at version 1.1.1 and supports ECMAscript 3.0. means ES3 version (1999)
    – Duc Le
    Jul 29, 2023 at 0:06

You must log in to answer this question.

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