Jump to content

step

Registered Users - Approved
  • Posts

    962
  • Joined

Everything posted by step

  1. Here's an example of how the entire rule could look: var first = Left(Field("FName"),1); var last = Field("LName"); return [first,last].filter(String).join("").replace(/\s|\'/g,"") + "@company.com";
  2. Don, you could put a text or graphic frame over your entire template and fill it with white and turn it on and off in the OnRecordStart rule based on the quantity field: FindTextFrame("white-text-frame").suppress = !!Field("Print Qty"); That being said, I think your current solution of adding an extra page to your template is a better method.
  3. Mike, one way you can control the spacing between the identifier and the number is to put each of them in separate columns of a table and then adjust the width of the columns. This is just some sample code that I think might help you out in this scenario: var numbers = [ "T: " + Field("Phone"), "C: " + Field("Cell"), "F: " + Field("Fax")]; var idWidth = 0.5; // inches var noWidth = 1.5; // inches // Filter empty numbers from the array numbers = numbers.filter(function(m){return m.replace(/[^\d]/g,'');}); // Start a table for the numbers var myTable = new FPTable; myTable.AddColumns(idWidth*7200, noWidth*7200); myTable.AddRows(numbers.length); // Add numbers for (var i=0; i<numbers.length; i++) { var id = numbers[i].replace(/([^\d]*)\d+/g,'$1'); var no = numbers[i].replace(/[^\d]*(\d+)/g,'$1'); myTable.Rows[i].SetContents(Trim(id), no); } return myTable.MakeTags();
  4. Sorry, I had originally named that variable "test" but forgot to change it everywhere else. I went back and edited the code in my first post. Reading in a multi-line text box does not create an array but splitting it does. So I split the string in that multiple line field by breaks ("<br>") in order to split the field into an array of rows.
  5. Is something like this what you're looking for? var data = Field("Your Multi-line Field"); data = data.replace(/[\n\r]/g,'<br>'); var row = data.split("<br>"); var myTable = new FPTable; myTable.AddColumns(4800, 4800, 4800, 4800); myTable.AddRows(row.length); for (var i=0; i<row.length; i++) { var column = row[i].split("|"); myTable.Rows[i].Cells[0].SetBorders("Thin","Black","Top","Bottom","Right","Left"); myTable.Rows[i].CopyCells(0,1,2,3); myTable.Rows[i].Cells[0].HAlign = "Center"; myTable.Rows[i].SetContents(column[0],column[1],column[2],column[3]); } return myTable.MakeTags();
  6. Is there a reason that you're attaching images of text rather than copying and pasting the code into code tags on the forum? It makes it pretty difficult to work with. Anyway, I think you can shorten the rule a lot to something like this: var firstName = (Field("ChooseFirstName") == "First Name") ? Trim(Field("First Name")) : Trim(Field("Nickname")); var middle = (Field("Middle") == "Yes") ? Trim(Field("MiddleInitial")) : ""; var last = Trim(Field("LastName")); var fullName = [firstName,middle,last].filter(String).join(" ").replace(/(\b[a-z](?!\.)\b)/gi,'$1.'); var result = [fullName,Trim(Field("Suffix")),Trim(Field("Designation"))].filter(String).join(", "); return result;
  7. I can't read the screenshot you attached so here's an example of how to do it using the replace function and a regular expression: var s = "W Kenny Massey Christine M Mostaert"; return s.replace(/(\b[a-z]\b)/gi,'$1.');
  8. You need to use superscript tags. Edits made in red: var s = Rule("Fit Name Degree Designation"); s = ReplaceSubstring(s, "LEED", "LEED<[color="Red"]superscript>[/color]®[color="red"]</superscript[/color]>"); return s;
  9. You can use the Left function to capture the first 3 characters of the string: Left(Field("number"),3);
  10. If you're wanting to make your current code work, you should make these edits (delete what's in red and add what's in green) var contact = [[color="red"][[/color]Field("Store1")[color="red"]][/color],[color="red"][[/color]Field("Store2")[color="red"]][/color],[color="red"][[/color]Field("Store3")[color="red"]][/color]]; var result = []; for(var i=0; i<3; i++){ if (contact[i][color="red"][1][/color] != "") { result.push(contact[i][color="red"].join(" ")[/color]); } } return (result.length>2) ? result.join(", ").replace(/^(.*)(, )(.*?)$/, "$1, and $3") : result.join(", ").replace(/^(.*)(, )(.*?)$/, "$1 [color="Lime"]&[/color] $3"); Since you're using FP9, you don't need the filter prototype at the beginning of that code or the for loop. I think this simplified code would work for you: var stores = [Field("Store1"),Field("Store2"),Field("Store3")]; // Array of stores stores = stores.filter(String); // Filter array to remove empties return (stores.length > 2 ) ? stores.join(", ").replace(/,\s([^,]*)$/,', and $1') : stores.join(" & ");
  11. Basically, I think your rule should be written so that it only adds the superscripted SM or TM or whatever you're trying to add when "ON DEMAND" is not followed by a "®" rather than on every occurrence of "ON DEMAND" and then trying to go back and remove it. Like this: return Field("BULLET_1").replace(/(ON DEMAND)(?!®)/gi,'$1<superscript>TM</superscript>');
  12. I saw the rule that you previously posted. I'm more so asking what the data in the "BULLET_1" field looks like.
  13. Can you post an example of the data? One example of a scenario where you'd want to add a superscripted trademark and one where you'd want to ignore it? I'm thinking you'd just search the string for "On Demand" being at the end of the string with a regular expression and then add the TM but I'd need to see how the data is coming to you to be certain.
  14. Don, here's a function I came up with that you can put in your JavaScript Globals of your template and call from your text boxes to determine whether or not you should be bolding the text: function useBold(date,time) { var d = new Date(); date = FormatDate(date,"m/d/yyyy"); // Set Date variables thisMonth = date.split("/")[0]; thisDay = date.split("/")[1]; thisYear = date.split("/")[2]; // Set Time variables thisHour = Int(time.split(":")[0]); thisHour += (time.search(/P/gi) > -1) ? 12 : 0; //add 12 hours if "PM" thisMinute = Int(time.split(":")[1]); // Set the date and time d.setMonth(thisMonth-1); d.setDate(thisDay); d.setFullYear(thisYear); d.setUTCHours(thisHour); d.setMinutes(thisMinute); var before5 = false; var weekend = (d.getDay() == 6 || d.getDay() == 0) ? true : false; // If it's the weekend go ahead and return true regardless of the time if (weekend) { return true; } // Determine if it's after 5 (17:00) if (d.getUTCHours() >= 17) { before5 = true; } return before5; } It requires that you pass the function (useBold()) two parameters: the date and the time. I wrote it with the data formatting structure that you quoted in your most recent post so as long as that's correct you should be all right. The function basically determines whether or not it's a weekend (Saturday or Sunday) or if it's after 5PM. If either of those conditions are met, it will return true. So I'm thinking you'd set your rules up as such: var s = "2/2/2014"; // Date Field var p = "4:00:00 PM" // Time Field var myFont = (useBold(s,p)) ? "Helvetica Bold" : "Helvetica"; return '<span font="' + myFont + '">' + FormatDate(s,"lm d, yyyy") + '</span>';
  15. You could set all of the pages to "unused" and change the code to: FusionPro.Composition.repeatRecordCount = 26; FusionPro.Composition.SetBodyPageUsage(FusionPro.Composition.repeatRecordNumber, true);
  16. Since your document is 2 pages it wants to impose these as a collated set. You can get around this by repeating each record twice (once for each page) and turning off the 2nd page the first time and the 1st page the second time. To do this you'll just need to add this to an OnRecordStart callback rule: FusionPro.Composition.repeatRecordCount = 2; FusionPro.Composition.SetBodyPageUsage(1, FusionPro.Composition.repeatRecordNumber == 1); FusionPro.Composition.SetBodyPageUsage(2, FusionPro.Composition.repeatRecordNumber == 2);
  17. Just convert both to all lowercase in the condition: if (ToLower(Field("RespondentName")) == ToLower(Field("HeadName"))) { return "<span>" + TaggedDataField("HeadAgencySur"); } else { return "<span>" + TaggedDataField("HeadName") + "</span>"; }
  18. It's doable. Without seeing an example of your template, I'll answer in the abstract how I would go about doing that: You essentially want to run your data file three times and turn on a different page for each "run." In order to do that you'll want import your data as an external data file and store it in an array and then tell FusionPro not to use the data file it's linked to (so that you can use the array instead). To tell FP not to use the file it's linked to add this to an OnJobStart rule: FusionPro.Composition.composeAllRecords = false; Now you'll have to tell FusionPro how many times it should create a record. In your case it will be 3 times the number of records you have in your data file (to create output for each page in your document). For this example I'm going to assume you only have 10 records. So add this line to the OnJobStart rule as well: FusionPro.Composition.endRecordNumber = 30 // 3 * 10 records Then you want to import your data as an External Data File: var exdata = new ExternalDataFileEx('/path/to/data.csv',','); From here you're kind of on your own (since I don't know what your data or template looks like) but you'll basically create an array to store those values in and reference them using the CurrentRecordNumber() function. Here are some good points of reference on those topics: External Data Files Arrays
  19. Would this work? newAddress = '<f name="MrEavesSanOT">' + Field("Address").replace(/(\d+)/g, '<f name="MrEavesModOT">$1<f name="MrEavesSanOT">'); return newAddress;
  20. To elaborate on the first regexp: return s.replace(/[color="Red"]([/color][color="Cyan"][color="Cyan"]™[/color][/color][color="Lime"]|[/color][color="Cyan"]®[/color][color="lime"]|[/color][color="Cyan"]*[/color][color="red"])[/color]/g,'<superscript>[color="red"]$1[/color]</superscript>'); The parentheses (in red) capture the match and store it in '$1' which I'm returning within the superscript tags The pipes (in green) indicate "or." So find the registration mark entity OR the trademark entity OR the asterisk entity. To add another entity, you would put another pipe after the asterisk entity followed by the new entity you're searching for. The items in blue are (obviously) the entities you're searching for. Just wanted to explain how that works for future reference.
  21. Don, try this. I edited the regexp to search for three HTML entities (instead of one single entity) and superscript the matches: var s = Field("Description New 1"); return s.replace(/(™|®|*)/g,'<superscript>$1</superscript>'); Alternatively, you could keep the same code that you have if you make some slight changes: var s = Field("Description New 1"); s = s.replace(/™/g,"<superscript>™</superscript>"); s = s.replace(/®/g,"<superscript>®</superscript>"); s = s.replace(/*/g,"<superscript>*</superscript>"); return s; Or do multiple replaces on a single return line: var s = Field("Description New 1"); return s.replace(/™/g,"<superscript>™</superscript>").replace(/®/g,"<superscript>®</superscript>").replace(/*/g,"<superscript>*</superscript>";
  22. I think the global function that David posted is a great solution to your question, Don. I did make a few adjustments to it, though, to illustrate yet another way to skin the cat. My edits remove the decimal before the superscripted cents since I know that's another frequently requested format. And also added a second conditional statement to handle cases where the price is lower than $1.00 (highlighted in red). function YourPrice(price) { var newYourPrice = ""; var trimPrice = price.replace(/[^\d\.]/g,''); // Strips out anything that's not a digit or a decimal var decimalPrice = FormatNumber("0.00", trimPrice); // Formats to 2 decimals var SuperPrice = decimalPrice.split(".")[1]; // Everything to the right of the decimal var NormalPrice = decimalPrice.split(".")[0]; // Everything to the left of the decimal if (price != "") { // If the price doesn't start with zeros, format as $x.xx if (NormalPrice.replace(/0/g,'')){ newYourPrice = "<superscript>$</superscript>"+NormalPrice+"<superscript>"+SuperPrice+"</superscript>"; } [color="Red"]// If the price is cents only, format as: xx¢ else { newYourPrice = SuperPrice + "<superscript>¢</superscript>"; }[/color] } return newYourPrice; }
  23. Based on the context of what you're trying to accomplish, I'm assuming you mean superscripting and not subscripting. There are two ways to alter the offset of the superscript: 1. In the text editor, click Paragraph > Global Settings and alter the superscript offset ratio until you find the positioning you like. Keep in mind that this change will be applied to all areas of your template where you're using superscripting. 2. You can edit rule to be something like this: return '<p br=false superoffset=45><superscript>$</superscript>5<superscript>00</superscript>'; Where the dollar sign and the '00' both have a superscript offset of 45%
  24. var zip = Field("Name"); return zip.replace(/\s/g,"<span><z newsize=9> </span>");
  25. Just globally replace the ampersands with the entity version like this: return "H&R Block".replace(/&/g,"&"); // returns "H&R Block"
×
×
  • Create New...