ricky10ss Posted May 25, 2018 Posted May 25, 2018 Attached is a sample data file with Slot1 - Slot68. Each slot could be a voucher or Coupon. The attached image shows what they are trying to do. The first character determines if the page selected is a coupon, voucher or blank. If a voucher then the next three character are the voucher number like SLOT35 in the sample data V203. If a coupon then the 2-3 character is the coupon code, 4-5 is the Service Type code, 6-11 in the mileage, and 12-15 is the value. Would need to parse each out to include the data into the coupon. Anyone have an idea on how to parse this out via Javascript? I could then turn on and off pages based on the it being a coupon, what version of coupon and/or if blank.Sample_Data.txt Quote
step Posted May 29, 2018 Posted May 29, 2018 You could use the substr method to parse the values from your string: // Your field here. var field = Field('SLOT1'); var type = field.substr(0, 1); switch (type) { case 'V': var code = field.substr(1, 3); break; case 'C': var code = field.substr(1, 2); var serviceCode = field.substr(3, 2); var mileage = field.substr(5, 6); var value = field.substr(11, 4); break; } Alternatively, you could use regular expressions to match the pattern: // Your field here. var field = Field('SLOT1'); var [type, code, serviceCode, mileage, value] = (field.match(/^(.)(.{2,3})(.{2})?(.{6})?(.{4})?$/) || [,'B']).slice(1); Quote
ricky10ss Posted May 29, 2018 Author Posted May 29, 2018 Thanks Ste. I was going to use a OnRecordStart rule that turns on the correct pages for the slots see example below. To use the parsed data in your example on each page do I need to create a rule for each field and data set I am trying to use? If I want to use Slot2 and value. Do I have to create a rule Slot2CouponValue? and Slot2CouponMileage for the mileage for Slot2? if (Field("SLOT1") != "") { FusionPro.Composition.SetBodyPageUsage("1",true) ; FusionPro.Composition.SetBodyPageUsage("2",true) ; } if (Field("SLOT2") != "") { FusionPro.Composition.SetBodyPageUsage("1",true) ; FusionPro.Composition.SetBodyPageUsage("2",true) ; } if (Field("SLOT3") != "") { FusionPro.Composition.SetBodyPageUsage("1",true) ; FusionPro.Composition.SetBodyPageUsage("2",true) ; FusionPro.Composition.SetBodyPageUsage("3",true) ; FusionPro.Composition.SetBodyPageUsage("4",true) ; } if (Field("SLOT4") != "") { FusionPro.Composition.SetBodyPageUsage("1",true) ; FusionPro.Composition.SetBodyPageUsage("2",true) ; FusionPro.Composition.SetBodyPageUsage("3",true) ; FusionPro.Composition.SetBodyPageUsage("4",true) ; } else return ""; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.