Javascript code for coupon - extract last 2 digits to pick ONE specific coupon in the mch:coupons schema
Hi ACC community,
I am working on a workflow where we are sending 2 different coupons.
We have created the coupon in adobe under the mch:coupons data schema.
One finishes with 10 and the other one with 15 and we would like to tell the JS code to pick the one that is finishing with either 10 for one audience and 15 for the other audience (we add them as an enrichment afterwards).
the JS code is working fine until we want to add the condition expr to pick that code ie. 1234ABCD10 (in red in the code below)
Here is the code - nonetheless to say that we have tried everything we know but it still returns the infamous red circle... I am desperate.
Would you be able to help? Thank you
var queryCoupon = xtk.queryDef.create(
<queryDef schema="mch:coupons" operation="getIfExists" lineCount="1">
<select>
<node expr="@id"/>
<node expr="@couponCode"/>
<node expr="@couponExpiryDate"/>
</select>
<where>
<condition expr={"@region='XX'"} />
<condition expr={"@type='WELCOME'"} />
<condition expr={"@startDate <= '"+formatDate(new Date(), "%2M/%2D/%4Y")+"'"} />
<condition expr={"@endDate >= '"+formatDate(new Date(), "%2M/%2D/%4Y")+"'"} />
<condition expr={"Right(@couponCode,2) == '15'"} />
</where>
<orderBy>
<node expr="@endDate" sortDesc="true"/>
</orderBy>
</queryDef>
);
vars.couponId = queryCoupon.ExecuteQuery().@id;
vars.couponCode = queryCoupon.ExecuteQuery().@couponCode;
vars.couponExpiryDate = queryCoupon.ExecuteQuery().@couponExpiryDate;
logInfo(vars.couponId,vars.couponCode);
if(vars.couponCode == null || vars.couponCode == "" ) {
logError( "Coupons details not found, Please add coupon details for the region.");
}
