Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 25th, 2018, 07:43 AM
ricky10ss ricky10ss is offline
Junior Community Member
 
Join Date: Mar 2009
Posts: 35
Default Parse data to determine page and extract data

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.
Attached Images
File Type: png Code example.png (27.5 KB, 8 views)
Attached Files
File Type: txt Sample_Data.txt (1.1 KB, 3 views)
Reply With Quote
  #2  
Old May 29th, 2018, 06:12 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Parse data to determine page and extract data

You could use the substr method to parse the values from your string:
Code:
// 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:
Code:
// Your field here.
var field = Field('SLOT1');
var [type, code, serviceCode, mileage, value] = (field.match(/^(.)(.{2,3})(.{2})?(.{6})?(.{4})?$/) || [,'B']).slice(1);
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #3  
Old May 29th, 2018, 10:04 AM
ricky10ss ricky10ss is offline
Junior Community Member
 
Join Date: Mar 2009
Posts: 35
Default Re: Parse data to determine page and extract data

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?

Quote:
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 "";
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:19 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.