Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > FusionPro® VDP Creator

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old October 20th, 2016, 11:10 AM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Help with conditional Rule

You're overthinking it and trying to apply a match rule written for phone numbers to email and web addresses. Not all rules have to be the same. in the above example, it would probably work to just have:

Code:
var numbers = [Field("Email"),Field("Website")];
return numbers.join('<color name="Pantone 801"> • </color>');
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #12  
Old October 21st, 2016, 09:45 AM
cmartin cmartin is offline
Junior Community Member
 
Join Date: Jun 2014
Posts: 15
Default Re: Help with conditional Rule

Thanks but my mistake for not giving all the details.

I am trying to do the same same as the phones.

They might not put the email or website in so the bullet will be added depending on which they put in. Same as the phone. That is why I was trying to use that one.
Reply With Quote
  #13  
Old October 21st, 2016, 10:41 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Help with conditional Rule

The way the code I wrote works is this:
  1. It creates an array of phone numbers which will be in this format: "f. ###.###.###"
  2. The filter method is applied to the array of numbers to remove the empty ones (more on this below).
  3. The remaining elements of the array are joined by a bullet.

The filter method is the part that I think is causing some confusion. If you take a look at its definition I've linked, you'll read that the filter method tests each element of the array against a function that will either return true or false. If the result is true, the element is kept. If it is false, it is removed from the array.

So, for the sake of this example, let's assume some values for your fields:
Rule("tagPhone1") = "d. "
Rule("Change phone format Rule") = "555.555.5555"
Rule("tagPhone2") = "f. "
Rule("Change phone format Rule") = ""

Code:
/*
 var office = "d. " + "555.555.5555";
 var fax = "f. " + ""; 
 */
var office = Rule("tagPhone1") + Rule("Change phone format Rule");
var fax = Rule("tagPhone2") + Rule("Change fax phone format Rule");

/*
 var numbers = ["d. 555.555.5555", "f. "]
 */
var numbers = [office, fax];
The comments in the code above show what happens to the code when a number ("Change fax phone format Rule" in this example) is empty.

We know that we want to get rid of the "f. " element since it doesn't have a corresponding number associated with it so we have to write a function for the filter array that will return false when an element doesn't fit the format of: "letter, period, space, phone number".

That can be done a number of ways but the way I chose was to remove elements that contained a space but did not have a character following the space. I'll name the function "HasCharacterAfterSpace" and re-write the code like this to better illustrate:
Code:
/*
 function HasCharacterAfterSpace(element) {
   return element.match(/.*\s(?=.)/);
 }

 // The below calls: HasCharacterAfterSpace("d. 555.555.5555"); <-- true
 // then calls     : HasCharacterAfterSpace("f. "); <-- false
 numbers = ["d. 555.555.5555", "f. "].filter(HasCharacterAfterSpace);
 
 // Values that returned false are removed from the array:
 numbers = ["d. 555.555.5555"];
 */
numbers = numbers.filter(function(m){return m.match(/.*\s(?=.)/);});
The next part is just joining the remaining elements in the array with something. In your case, you're joining them with a bullet wrapped in color tags but it could be anything you like. And as is the case in this example, arrays containing only one element won't be "joined" but will still be converted to a string.

It's also worth noting that arrays can contain more than two elements. So you could have all of your phone numbers in one array like this:
Code:
var numbers [ 
  "d. 555.555.5555", 
  "f. ",
  "c. 444.444.4444"
];

// returns 'd. 555.555.5555 <color name="PANTONE 801"> • </color>c. 444.444.4444';
return numbers.filter( function(element){ 
  return element.match(/.*\s(?=.)/);
}).join('<color name="PANTONE 801"> • </color>');
Hopefully that gives you a better understanding of what the code is doing and how to make the filtering work for an array of elements that likely don't contain any spaces (websites and email address).
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
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 12:25 AM.


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