Jump to content

step

Registered Users - Approved
  • Posts

    962
  • Joined

Everything posted by step

  1. Whoops I forgot to get the record from the external data field. Try this: var externalDF = new ExternalDataFileEx("Competitor-ExDF.xlsx", "Excel"); var unique = function (value, index, self) { return value ? self.indexOf(value) === index : false; }; var getResource = function (value) { [color="Red"]var competitor = externalDF.FindRecord("CompetitorDropDown", value); if (competitor) { var competitorImage = externalDF.GetFieldValue(competitor, "CompetitorImage"); if (competitorImage) { return Resource(competitorImage).content; } } return '';[/color] }; return ["CP-Product-1-A", "CP-Product-1-B", "CP-Product-1-C"] .map(Field) .filter(unique) .map(getResource) .filter(String) .join(' ');
  2. Would this work? var externalDF = new ExternalDataFileEx("Competitor-ExDF.xlsx", "Excel"); var unique = function (value, index, self) { return value ? self.indexOf(value) === index : false; }; var getResource = function (value) { var fieldValue = externalDF.GetFieldValue(value, "CompetitorImage"); return fieldValue ? Resource(fieldValue).content : ''; }; return ["CP-Product-1-A", "CP-Product-1-B", "CP-Product-1-C"] .map(Field) .filter(unique) .map(getResource) .filter(String) .join(' ');
  3. Is the maximum number of concurrent usages of FusionPro 10 Server something that is tied to your license or is it a configuration that can be adjusted? I vaguely recall it being a configuration in earlier versions of FP but I can't find it anywhere in FP10. I have two different Windows 2012 servers set up with FusionPro VDP Producer (API) 10.0.3: Server 1: 8GB RAM; 2.30GHz CPU; 4 (virtual) processors - allows only 1 composition Server 2: 16GB RAM; 2.30GHz CPU; 8 (virtual) processors - allows 3 concurrent compositions I'm not sure the specs of our FusionPro 9 servers but we used to be able to get 16 concurrent compositions per server. Needless to say, this is shift is somewhat crippling. Any ideas on what I'm missing?
  4. You're comparing strings rather than dates. You should convert them to actual dates: var birthday = new Date(Field('BIRTH_DATE')); var cutoff = new Date('08/31/1963'); var file = birthday > cutoff ? 'Entertainment' : 'Better with Age Day_new'; return Resource(file + ' TL_Sept.jpg');
  5. You could try this in your OnRecordStart callback: // All pages to compose during composition. var pagesToImpose = [3, 4, 5, 6]; var page = 0; while (++page) { try { var compose = pagesToImpose.indexOf(page) > -1 || IsPreview(); FusionPro.Composition.SetBodyPageUsage(page, compose); } catch (e) { break; } }
  6. I bet you're variable is actually returning a non-breaking space character ( ) rather than an actual space. Try this: return RawTextFromTagged(Field("Partner Code")).replace(/\s/g, '');
  7. Because cases have been set for all other scenarios. If none of the cases evaluated to true, then it stands to reason that the only remaining option would be the 72x36 size. Check out this reference on switch statements to get a better understanding. That's leads me to believe that you haven't accurately described the values your "Years of Service" field contain. I can't really help you any further without seeing an example of your data/template.
  8. 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);
  9. Yes, I know. But you only have 3 size options. The switch statement determines which size to use. From there, the style is appended to the size to create the page name. Are you saying that the value of the "Years of Service" field is a string value representing a range of numbers (like "1-5") or just that the user will never enter a number outside of those specified ranges (like 6)? The latter of which shouldn't make a difference and the code should still work. But, if the values are string ranges, you could modify the code like this: var background = Field("Background") || 'Style 1'; switch (Field("Years of Service")) { case '1-5': case '10-15': size = '18x12'; break; case '20-25': size = '60x30'; break; default: size = '72x36'; } FusionPro.Composition.SetBodyPageUsage(background + " " + size, true); Right, and again, that's what the code I posted is doing. It determines the size needed based on the "Years of Service" and adds the style selected from the drop down list to it.
  10. Both of those variables are set to the same value. Is that intentional? I don't think that will work. If I'm understanding correctly, Gdellaiera is trying to determine which page to use here based on the "Years of Service" field and appending the style to the end of the string. So the correct syntax would be: /** * When the vale of the "Years of Service" field is between 10-15, the * page size should be 18x12 regardless of the style selected in the * "Background" field. So set the `page` variable to the appropriate size * and append the style to the end to dynamically cover all three styles. */ if (Field("Years of Service") >=10 && Field("Years of Service")<= 15) { var page = "18x12 " + Field("Background"); } I think a better way to accomplish this task would be: // Get the "Years of Service" value and cast it as an integer for comparisons. // Default the value to `1` when the field is empty. var yearsOfService = Int(Field("Years of Service")) || 1; // Get the style value from the "Background" field. // Default to `Style 1`. var background = Field("Background") || 'Style 1'; // Use a switch statement to determine which page size we should be using. We'll // set the `size` variable to the first expression that evaluates to `true`. switch (true) { // Check to see if the `yearsOfService` is 15 or less. If it is, we can set the // size to 18x12 and none of the other expressions in this `switch` will be evaluated. case yearsOfService <= 15: size = '18x12'; break; // If the `yearsOfService` is more than 15, we will check to see if the // `yearsOfService` field is 25 or less. If it is, set the size to 60x30. case yearsOfService <= 25: size = '60x30'; break; // If neither of the two previous cases were true, that means the `yearsOfService` // is greater than 25, so we can set the size to 72x36. default: size = '72x36'; } // Since you've already set all of the body pages to `false`, you only need to // enable the correct page. FusionPro.Composition.SetBodyPageUsage(background + " " + size, true);
  11. Use span tags? team.members.push({ team: [color="Red"]'<span font="Arial" color="white">'[/color] + ToUpper(teamname) + [color="red"]'</span>'[/color], name: Field('Name' + i), headshot: CreateResource(Field('Headshot' + i), 'graphic', true), titleone: Field('TitleOne' + i), titletwo: Field('TitleTwo' + i) });
  12. The team names in the 'teams' object need to match (case-sensitive) the team names in your data. So, in this case, you could modify the object definition to be: var teams = { [color="Red"]'Onsite Team'[/color]: { color: [72, 15, 0, 0] }, [color="Red"]'Service Leadership'[/color]: { color: [94, 68, 1, 0] }, [color="Red"]'Support Team'[/color]: { color: [64, 6, 100, 0] }, [color="Red"]'Regional Team'[/color]: { color: [86, 30, 55, 9] } } There are two other changes to note: team.members.push({ team: ToUpper(teamname), name: Field('Name' + i), headshot: CreateResource(Field('Headshot' + i)[color="red"], 'graphic', true[/color]), titleone: Field('TitleOne' + i), titletwo: Field('TitleTwo' + i) }); person.headshot.content.replace('/>', 'width="' + [color="red"]([/color]colWidth - picCell.Margins.Left - picCell.Margins.Right[color="red"])[/color] + '"/>') : '';
  13. var XDF = new ExternalDataFileEx("PostcardContent.txt", "\t"); var s = XDF.GetFieldValue(XDF.FindRecord(0, Field('Header')), 1) || Field('HeaderCustom'); s = ReplaceSubstring(s, "[COMMUNITY NAME]", Field("Community Name")); s = ReplaceSubstring(s, "[RSVP]", Field("RSVPPhone")); return s;
  14. Because your site is sending back the "option" the user selected rather than the value of the option the user selected, I think you'll have to continue referencing the external data file. That being said, you can certainly simplify things. You consolidate your two "header" rules into one: var XDF = new ExternalDataFileEx("PostcardContent.txt", "\t"); return XDF.GetFieldValue(XDF.FindRecord(0, Field('Header')), 1) || Field('HeaderCustom'); The above code will search for a value in the first column of your data file that matches the value of the "Header" field. If found, the corresponding value of the second column will be returned. If nothing is found, it will return the value of the "HeaderCustom" field. I set that up in accordance to the rule you supplied but I would think the value of the custom field would take precedence over the pre-written options. If that's the case, you can just reverse the order: var XDF = new ExternalDataFileEx("PostcardContent.txt", "\t"); return Field('HeaderCustom') || XDF.GetFieldValue(XDF.FindRecord(0, Field('Header')), 1);
  15. I think you could use a table to achieve that layout. Each team member would be made up of two rows: the first row would be their team name and the second row would be there headshot/name/etc. Then you'd just horizontally straddle the first row for team members on the same team. The tricky part, in my mind, is the fact that the team names don't just butt up to each other. So considering that, I would add two additional columns on each team member's table – one on the left and one on the right. These columns won't have any content but will allow us to manipulate the gap between each team member. The benefit over simply increasing the margins on our cells is that we can still allow the team name headers to straddle the dummy columns. Anyway, I'm sure there's probably a better/more efficient way to do this but I thought I'd give it shot: var columns = 6; var rows = 4; var teams = { 'onsite team': { color: [72, 15, 0, 0] }, 'service leadership': { color: [94, 68, 1, 0] }, 'support team': { color: [64, 6, 100, 0] }, 'regional team': { color: [86, 30, 55, 9] } } // Assumes Field names: Name1, Team1, Headshot1, Title1, etc for (var i = 1; i <= columns * rows; i++) { var teamname = Field('Team' + i); if (!(team = teams[teamname])) continue; if (!team.members) { team.members = []; // Create the color for this team. FusionProColor.apply(null, [teamname].concat(team.color)); } team.members.push({ team: ToUpper(teamname), name: Field('Name' + i), headshot: CreateResource(Field('Headshot' + i) + '.pdf', 'graphic', true), title: Field('Title' + i) }); } var data = []; for (var team in teams) { if (members = teams[team].members) data = data.concat(members); } // Return nothing if no data was found. if (!data.length) return ''; // Table configuration. var colWidth = 1.5 * 7200; // 1.5" Column var spaceBetweenColumns = 0.125 * 7200; // 1/8" Space between columns var table = new FPTable(); // Add the columns to the table definition. for (var col = 0; col < columns * 3; col++) { var width = col % 3 == 1 ? colWidth : spaceBetweenColumns / 2; table.AddColumn(width); } while (data.length) { var people = data.splice(0, columns); var team = false; var teamRow = table.AddRow(); var picRow = table.AddRow(); // Global styles. [teamRow, picRow].map(function (row) { var cell = row.Cells[0]; cell.HAlign = 'Center'; cell.VAlign = 'Middle'; cell.Margins = { 'Top': spaceBetweenColumns / 10, 'Bottom': spaceBetweenColumns / 10, 'Left': 10, 'Right': 10 }; row.CopyCells.apply(row, row.Cells.map(function (s, p) { return p; })); row.minHeight = 1800; }); for (var i = 1; i <= teamRow.Cells.length && people.length; i += 3) { var person = people.shift(); var teamCell = teamRow.Cells[i]; var picCell = picRow.Cells[i]; if (team && person.team == team.Content) { team.HStraddle += 3; } else { teamCell.ShadeColor = person.team; teamCell.ShadePct = 100; teamCell.HStraddle = 1; teamCell.Content = person.team; team = teamCell; } var headshot = person.headshot.exists ? person.headshot.content.replace('/>', 'width="' + colWidth - picCell.Margins.Left - picCell.Margins.Right + '"/>') : ''; picCell.Content = [headshot, person.name, person.title].filter(String).join('<br>'); } } return table.MakeTags();
  16. There isn't a way to highlight text in FusionPro. If you posted your template, some sample data, and an example of what you're trying to achieve, it might be possible to come up with a solution that gives you the results you're looking for by using other means (for example: a table with cell shading).
  17. What version of FusionPro are you using? FusionPro 10 offers a built-in method of handling this scenario. You could look up "FusionPro.GetMultiLineRecords()" Otherwise, if you could post your template/data it would be easier to help you.
  18. The main issue is that you have multiple if/else statements when you really want to use a switch statement or a big if/else if/else statement. Let's assume, for example, the value of the 'version' field is 'CORALVILLE': if (Field("version") == "CORALVILLE") // TRUE { FusionPro.Composition.SetBodyPageUsage("Coralville 1", true) // This page is enabled FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", false) // This page is disabled FusionPro.Composition.SetBodyPageUsage("Coralville 2", true) // This page is enabled FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", false) // This page id disabled } else { // --------------------- FusionPro.Composition.SetBodyPageUsage("Coralville 1", false) // Since the first condition FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", true) // was met, this else block FusionPro.Composition.SetBodyPageUsage("Coralville 2", false) // does not execute. FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", true) // ----------------------- } if (Field("version") == "NORTHLIBERTY") // FALSE { FusionPro.Composition.SetBodyPageUsage("NorthLiber ty1", true) // ------------------------ FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", false) // Since version is not NORTHLIBERTY FusionPro.Composition.SetBodyPageUsage("NorthLiber ty2", true) // this does not execute. FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", false) // ------------------------ } else { FusionPro.Composition.SetBodyPageUsage("NorthLiber ty1", false) // This page is disabled FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", true) // This page is enabled FusionPro.Composition.SetBodyPageUsage("NorthLiber ty2", false) // This page is disabled FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", true) // This page is enabled } if (Field("version") == "WASHINGTON") // FALSE { FusionPro.Composition.SetBodyPageUsage("Washington 1", true) // ------------------------- FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", false) // Since version is not WASHINGTON FusionPro.Composition.SetBodyPageUsage("Washington 2", true) // this does not execute. FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", false) // ------------------------- } else { FusionPro.Composition.SetBodyPageUsage("Washington 1", false) // This page is disabled FusionPro.Composition.SetBodyPageUsage("CedarRapid s1", true) // This page is enabled FusionPro.Composition.SetBodyPageUsage("Washington 2", false) // This page is disabled FusionPro.Composition.SetBodyPageUsage("CedarRapid s2", true) // This page is enabled } return ""; As you can see, you'll end up with Coralville AND CedarRapids pages enabled. You could simplify things a lot by replacing all of that code with: var pages = ['Coralville', 'CedarRapids', 'NorthLiberty', 'Washington']; var version = Field("version"); for (var i in pages) { var page = pages[i]; var enable = new RegExp(page, 'i').test(version); FusionPro.Composition.SetBodyPageUsage(page + '1', enable); FusionPro.Composition.SetBodyPageUsage(page + '2', enable); }
  19. Is the paragraph itself variable? Would making the entire paragraph and the "hand drawn circle" that surrounds it an image suffice? It would be easier to offer a better solution if you could collect your template and attach it to the forum.
  20. Would this work? var logo = Field("SecondaryLogo") ? Field("SecondaryLogo") : Field("PrimaryLogo"); return CreateResource(logo, 'graphic', true);
  21. You could do it by tracking how many times each account number has been used by adding them to a global object: JavaScript Globals var accounts = {}; OnRecordStart var FP = FusionPro.Composition; var accountNumber = Field('AccountNo'); if (!accounts[accountNumber]) { accounts[accountNumber] = 1; } else { accountNumber += '_' + ++accounts[accountNumber]; } FP.OpenNewOutputFile(accountNumber + '.' + FP.outputFormatExtension);
  22. Try putting your logic in a function (called "validateTextFrames" for example) and then call it from your OnRecordStart callback. JavaScript file: function validateTextFrames() { // Your required frames. var frames = [ 'Your First Text Frame Name', 'Your Second Text Frame Name' ]; for (var i in frames) { try { var frameName = frames[i]; if (FindTextFrame(frameName)) delete frames[i]; } catch (e) {} } if ((frames = frames.filter(String)).length) ReportError('Missing required text frame(s):\n"' + frames.join('"\n"') + '"'); } OnRecordStart callback: Load("errortest.js"); validateTextFrames(); As far as returning a value from your external JS file, you have to return the function in your FP callback: JS file: function testReturn() { return 'hello from your external js file!'; } OnRecordStart: Load("errortest.js"); return testReturn();
  23. No, sorry, I've just been busy. Try this: var numOfCols = 3; var data = FusionPro.GetMultiLineRecords(); var table = new FPTable(); table.AddColumns(6000, 7000, 3000); var header = table.AddRow(); header.Type = 'Header'; header.Cells[0].SetBorders('Thin', 'Black', 'Bottom'); header.CopyCells(0, 1); header.SetContents('Date', 'Amount'); for (var i = 1; i <= data.recordCount; i++) { function ExField(str) { return TaggedTextFromRaw(data.GetFieldValue(i, str)); } // Skip this record if 'Date' & 'Amount' fields are both empty. var contents = ['Date', 'Amount'].map(ExField); if (!Trim(contents.join(''))) continue; var row = table.AddRow(); row.SetContents.apply(row, contents); } // Determine how many columns are needed based on how many rows // were added to the table (minus 1 for the header row). var colsNeeded = table.Rows.length - 1; // Number of rows needed to evenly distribute across numOfCols. var rows = Math.ceil(colsNeeded / numOfCols); // Duplicate column 1 and 2 (and their headers) to make up numOfCols. for (var i = 0; i < (numOfCols - 1) * 3; i++) { table.Columns.push(table.Columns[i % 3]); table.Rows[0].Cells.push(table.Rows[0].Cells[i % 3]) } // Concatenate the rows cells in order to reduce our total rows // and fill up the extra columns. var rowCounter = 1; while (colsNeeded > rows) { var index = rowCounter % rows || rows; var row = table.Rows.splice(rows + 1, 1).pop(); table.Rows[index].Cells = table.Rows[index].Cells.concat(row.Cells) rowCounter++ } [color="Red"]// Create reference variables to the cells of the first row (header) // and second row (the date/amount values). var [headerCells, contentCells] = table.Rows.slice(0, 2).map(function(s) { return s.Cells }); // We only need as many header cells as there are content cells. So, if // there are more header cells than content cells, we can begin removing // headers until the columns are equal. while (headerCells.length > contentCells.length) headerCells.pop();[/color] // Return the table tags. return table.MakeTags();
  24. I haven't tested this but it seems like it would give you what you're looking for: var numOfCols = 3; var data = FusionPro.GetMultiLineRecords(); var table = new FPTable(); table.AddColumns(6000, 7000, 3000); var header = table.AddRow(); header.Type = 'Header'; header.Cells[0].SetBorders('Thin', 'Black', 'Bottom'); header.CopyCells(0, 1); header.SetContents('Date', 'Amount'); for (var i = 1; i <= data.recordCount; i++) { function ExField(str) { return TaggedTextFromRaw(data.GetFieldValue(i, str)); } [color="Red"] // Skip this record if 'Date' & 'Amount' fields are both empty. var contents = ['Date', 'Amount'].map(ExField); if (!Trim(contents.join(''))) continue;[/color] var row = table.AddRow(); row.SetContents.apply(row, contents); } [color="red"]// Determine how many columns are needed based on how many rows // were added to the table (minus 1 for the header row). var colsNeeded = table.Rows.length - 1;[/color] [color="red"]// Update the numOfCols variable if we need less than 3. numOfCols = colsNeeded < numOfCols ? colsNeeded : numOfCols;[/color] // Number of rows needed to evenly distribute across numOfCols. var rows = Math.ceil(colsNeeded / numOfCols); // Duplicate column 1 and 2 (and their headers) to make up numOfCols. for (var i = 0; i < (numOfCols - 1) * 3; i++) { table.Columns.push(table.Columns[i % 3]); table.Rows[0].Cells.push(table.Rows[0].Cells[i % 3]) } // Concatenate the rows cells in order to reduce our total rows // and fill up the extra columns. var rowCounter = 1; while (colsNeeded > rows) { var index = rowCounter % rows || rows; var row = table.Rows.splice(rows + 1, 1).pop(); table.Rows[index].Cells = table.Rows[index].Cells.concat(row.Cells) rowCounter++ } // Return the table tags. return table.MakeTags();
×
×
  • Create New...