Jump to content

Parse data to determine page and extract data


Recommended Posts

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

Codeexample.png.f89af305eec211504476a7080376a8c8.png

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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 "";

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...