I'm trying to create dynamic content to my journey email based on Salesforce data, so the synchronised contact data extension. I have the AMPscript code below, which I've tried but cannot get it to work. Basically what I want to do:
In the first journey email, a couponcode will be distributed for our online store from the DE called "BirthdayCouponCodes2024". All of the unique coupon codes in the DE start with "BDAY24-U16", so they are e.g. "BDAY24-U16-GT65D2SA"
In the second journey email I want to check if the person has used the couponcode already. The couponcodes the person has used are updated to Salesforce and from there to the synchronised contact DE in Marketing Cloud. The column name is "Shopify_Discount_Codes__c" and the used couponcodes are populated like this "COUPOCODE1;COUPOCODE2;BDAY24-U16-GT65D2SA".
If they have used the code, i.e. a couponcode that starts with "BDAY24-U16" can be found from the contact data in Salesforce, I don't want to show anything to them in the dynamic content.
If they haven't used the code, i.e. there is no couponcode that starts with "BDAY24-U16" in the contacts data in Salesforce, I want to show a reminder text about the coupon, with the unique code that was fetched from the "BirthdayCouponCodes2024" DE for the specific subscriber in the first email.
I'm trying to use the AMPscript IndexOf function for this, as I have understood that I could use it to check if a string contains a specific substring, and that this function returns -1 if the substring is not found. However, I cannot get this to work in my tests, and even though the "BDAY24-U16" code does not exist in the column, I do not get the dynamic text reminding to use the code.
Can I not use AMPscript this way? Would there be another way to do this? Really appreciate any help here!
Here is the AMPscript code that I have tested with:
%%[set @subKey = AttributeValue("_subscriberkey")set @discountCode = Lookup("Contact_Salesforce", "Shopify_Discount_Codes__c", "Contact_ID_18__c", @subKey)set @rowset = LookupRows("BirthdayCouponCodes2024", "EmailAddress", emailaddr)set @row = Row(@rowset, 1)]%%%%[if IndexOf(@discountCode, "BDAY24-U16") == -1 then]%% %%[if RowCount(@rowset) > 0 then]%%<p style="text-align: center; font-size: 18px"><span style="color: #000000">Remember to use your code:</span></p><p style="text-align: center; font-size: 22px"><span style="color: #DB0661">%%=Field(@row, "couponCode")=%%</span></p><p style="text-align: center; font-size: 15px; color: #000000; font-style: italic;"> Valid for 30 days.</p> %%[endif]%%%%[endif]%%