#1
|
|||
|
|||
![]()
I am trying to create an on-line FusionPro template of a "phone book".
I want to offer the following functionality: - User enters (into one large text box?) a list of names and corresponding phone numbers. - when they click the 'Refresh Preview' button (i.e. onRecordStart?), the list they entered is returned, sorted alphabetically. Is it possible to write a JavaScript rule that does this? Here's one thing to keep in mind... For each NAME, I need to associate a PHONE NUMBER So for example, if I enter the following data: John Smith 858-123-4567 Adam Rodriguez 986-456-7894 Robert Hoo 201-457-7847 ... I should get this back: Adam Rodriguez 986-456-7894 John Smith 858-123-4567 Robert Hoo 201-457-7847 (The list was sorted alphabetically, and the phone numbers "moved" with the corresponding name) Can I bribe someone with an amazon.com gift certificate if they can help me pull this off?
__________________
-- Eric Carbone IT/Project Manager, MOR Printing Inc. Windows 10 |Adobe Acrobat XI | FusionPro 9 |
#2
|
||||
|
||||
![]()
Sure, sorting data alphabetically is absolutely possible. JavaScript is great for this kind of stuff.
Exactly how is the data presented to FusionPro? Is it all in one field with some kind of intra-field delimiter? Or an external data file? Are the phone numbers already associated with the names in the data? At any rate, if you can get the data into an array, you can just use the native Array.sort method in JavaScript: https://developer.mozilla.org/En/Cor...cts/Array/Sort Sorts are done by simple string comparison by default, so if you're simply sorting by first name, there's not much to do. (Although I'm not sure I would sort by first name in a real-world application, but that's just me.) Code:
var myArray = [ "John Smith 858-123-4567", "Adam Rodriguez 986-456-7894", "Robert Hoo 201-457-7847" ]; return myArray.sort().join("<br>\n"); Code:
var myData = "John Smith 858-123-4567,Adam Rodriguez 986-456-7894,Robert Hoo 201-457-7847"; var myArray = myData.split(","); return myArray.sort().join("<br>\n");
__________________
Dan Korn FusionPro Developer / JavaScript Guru / Forum Moderator PTI Marketing Technologies | Printable | MarcomCentral I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com. Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs. This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data. Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages. Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance. Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support. How To Ask Questions The Smart Way The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript. Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5. return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)}); ![]() |
#3
|
|||
|
|||
![]()
Hi Dan,
Good stuff! Well to answer your question regarding HOW the user would input the list ... This is for a printOne site, so my options are: 1. Create 50 blank fields, and allow the user to enter (up to) 50 names. (Then I suppose I'd aso have to have 50 more fields, for the phone numbers). This makes for a very large form that the user has to fill out. And what happens when the user has MORE than 50 entries? I'd have to add even more fields. So I guess this method is not practical. 2. The second option (as far as I know) is to present the user with one large multi-line text box and say "Type all of your names and phone numbers in here, separated by a comma" (or some other type of delimiter). It would probably look messy but this is the only other input method I can think of. (Having the user upload a data file of some sort would not be practical (not for this client anyway)) So some questions... 1. Instead of asking the user to enter one long, continuous line of names and phone numbers separated by commas, CAN the user simply press the return key after each name/number pair is entered? In other words can they enter this... John Smith 858-123-4567 Adam Rodriguez 986-456-7894 Robert Hoo 201-457-7847 ... instead of this... John Smith 858-123-4567, Adam Rodriguez 986-456-7894, Robert Hoo 201-457-7847 2. Assuming this multi-line text box can accept this data, and assuming the name of the text box is txtAccounting, can you help me construct the correct JavaScript code? 3. Where exactly do I put this code? Do I place it inside of OnRecordStart ?
__________________
-- Eric Carbone IT/Project Manager, MOR Printing Inc. Windows 10 |Adobe Acrobat XI | FusionPro 9 |
#4
|
||||
|
||||
![]() Quote:
Quote:
It can be in any regular rule that returns its results to a text frame in your template. Again, it depends on what you're trying to do.
__________________
Dan Korn FusionPro Developer / JavaScript Guru / Forum Moderator PTI Marketing Technologies | Printable | MarcomCentral I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com. Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs. This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data. Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages. Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance. Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support. How To Ask Questions The Smart Way The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript. Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5. return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)}); ![]() |
#5
|
|||
|
|||
![]()
Dan, I tested the array rule you have here using the data typed into the rule and it works great. I am wondering how I would use an external data file to accomplish this same thing. I have attached a sample data file, these are in alphabetical order right now but won't be when I run the job. How would I write the rule with each option being in it's own field. I would want to ignore the first field in the external data file though, that field is what I am going to try and link the source data to. TIA
I tried this but get an error "myData.split is not a function" Code:
var myData = new ExternalDataFileEx("BeerListHeader.txt", "\,"); var myArray = myData.split("\,"); return myArray.sort().join("<br>\n");
__________________
Don Reimer - JavaScript Novice MAC OS 10.14.6 Acrobat DC FP Creator 12.0.1 Last edited by dreimer; July 25th, 2013 at 02:11 PM.. |
#6
|
||||
|
||||
![]()
Are you composing your template using only the external data file? Or are you referencing the external data file's kit number to determine which beer list to pull in?
If it's the former: OnRecordStart() Code:
var exData = new ExternalDataFileEx("BeerListHeader.txt",','); // Initialize External Data file var ordered = []; //Initialize the array var frameName = "BeerList"; // Name of the text frame you want the list to appear in // Populate the array with columns 1-8 of your external data list for (var i=1; i<=8; i++){ ordered.push(exData.GetFieldValue(FusionPro.Composition.inputRecordNumber,i)); } // Remove blanks from the array for (var n=0; n<ordered.length; n++){ if (ordered[n] == "") { ordered.splice(n,1); n--; } } // Put the contents of the array in alphabetical order // Join the contents with break tags ordered = ordered.sort().join("<br>"); FindTextFrame(frameName).content = ordered; New Text Rule Code:
var exData = new ExternalDataFileEx("BeerListHeader.txt",','); // Initialize External Data file var ordered = []; //Initialize the array var kitField = "Kit#"; // Name of field in data to match the kit number in the external data file // Populate the array with columns 1-8 of your external data list for (var i=1; i<=8; i++){ ordered.push(exData.GetFieldValue(exData.FindRecord("Kit",Field(kitField)),i)); } // Remove blanks from the array for (var n=0; n<ordered.length; n++){ if (ordered[n] == "") { ordered.splice(n,1); n--; } } // Put the contents of the array in alphabetical order // Join the contents with break tags ordered = ordered.sort().join("<br>"); return ordered;
__________________
Ste Pennell FusionPro VDP Creator 9.3.15 Adobe Acrobat X 10.1.1 Mac OS X 10.12 |
#7
|
|||
|
|||
![]()
Wow, thanks.
Not sure at this point, could go either way. So for now I tried using the first one not having to match source data. I get an error "ordered is not defined". Is that function for newer versions of FP?
__________________
Don Reimer - JavaScript Novice MAC OS 10.14.6 Acrobat DC FP Creator 12.0.1 Last edited by dreimer; July 25th, 2013 at 02:49 PM.. |
#8
|
|||
|
|||
![]()
Scratch that, didn't use it as a OnRecordStart rule. Works great. One thing, I want to have it populate into three columns of my text frame. I have that set and it works, but how would I get the text centered and not left justified since it is a OnRecordStart Rule. Guess I would have to figure out how to change the font as well. Thanks for the help!!!!
__________________
Don Reimer - JavaScript Novice MAC OS 10.14.6 Acrobat DC FP Creator 12.0.1 |
#9
|
|||
|
|||
![]()
Second one works great too! I just used the same external file as my source file to test it. This one is going to work best I think since this way I have the text box options available as opposed to the OnRecordStart rule.
And once again thank you for your help with many of my questions over the years. Glad to have the people we do on this forum!!!
__________________
Don Reimer - JavaScript Novice MAC OS 10.14.6 Acrobat DC FP Creator 12.0.1 |
#10
|
||||
|
||||
![]()
One thing you could try is to put some text in the text box and use the text editor to format it the way you want. When the OnRecordStart rule runs, it will override the content of that frame with the beer list but will hold the formatting.
__________________
Ste Pennell FusionPro VDP Creator 9.3.15 Adobe Acrobat X 10.1.1 Mac OS X 10.12 |
![]() |
Tags |
alphabetically, alphabetize, array, sort |
Thread Tools | Search this Thread |
Display Modes | |
|
|