JulieP Posted May 13, 2010 Share Posted May 13, 2010 I am trying to build a business card template with eleven possible lines. If one line is left blank, the others should move up. I tried using Dan Korn's code example in his Oct 7th '08 post. I thought I could make it work but I get this error on validation "Function does not return a value". I would greatly appreciate if someone could steer me in the right direction. Here is my clunky code: //I have eleven possible fields, if certain fields are left blank all the other fields need to move up 1 line. //Field Rule Vars var Office = Rule("OFFICERemoveWriteRule"); var Mobile = Rule("MOBILERemoveWriteRule"); var Email = Rule("EMAILRemoveWriteRule"); var Twitter = Rule("SuppressTwitGraph"); var TwitAdr = Rule("twitadrRemoveWriteRule"); var FaceBook = Rule("Suppress Facebk graphic"); var FaceBkAdr = Rule("facebkadrRemoveWriteRule"); var CampusOffice = Rule("CampusOfficeRemoveWriteRule"); var OfficeAddress = Rule("OfficeAdrRemoveWriteRule"); var Phone = Rule("PHONERemoveWriteRule"); var Fax = Rule("FAXRemoveWriteRule"); var CampusWebsite = Rule("WEBSITERemoveWriteRule"); //Field Vars var Ofc = Office ? Office : ""; var Mob = Mobile ? Mobile : ""; var Eml = Email ? Email : ""; var TwitG = Twitter ? Twitter : ""; var TwitA = TwitAdr ? TwitAdr : ""; var FbkG = FaceBook ? FaceBook : ""; var FbkA = FaceBkAdr ? FaceBkAdr : ""; var CampOff = CampusOffice ? CampusOffice : ""; var OffAdr = OfficeAddress ? OfficeAddress : ""; var Phn = Phone ? Phone : ""; var FX = Fax ? Fax : ""; var CampWeb = CampusWebsite ? CampusWebsite: ""; var line1 = ""; var line2 = ""; var line3 = ""; var line4 = ""; var line5 = ""; var line6 = ""; var line7 = ""; var line8 = ""; var line9 = ""; var line10 = ""; var line11 = ""; if(Ofc && Mob && Eml && TwitA && FbkA && CampOff && OffAdr && Phn && FX && CampWeb) { line1 = Ofc; line2 = Mob; line3 = Eml; line4 = TwitG + TwitA; line5 = FbkG + FbkA; line6 = ""; line7 = CampOff; line8 = OffAdr; line9 = Phn; line10 = Fax; line11 = CampWeb; } else //no Office if(Mob && Eml && TwitA && FBKA && CampOff && OffAdr && Phn && FX && CampWeb) { line1 = Mob; line2 = Eml; line3 = TwitG + TwitA; line4 = FbkG + FbkA; line5 = ""; line6 = CampOff; line7 = OffAdr; line8 = Phn; line9 = Fax; line10 = CampWeb; line11 = "" } else //no Mobile if(Ofc && Eml && TwitA && FbkA && CampOff && OffAdr && Phn && FX && CampWeb) { line1 = Ofc; line2 = Eml; line3 = TwitG + TwitA; line4 = FbkG + FbkA; line5 = ""; line6 = CampOff; line7 = OffAdr; line8 = Phn; line9 = Fax; line10 = CampWeb; line11 = ""; } else //no Twitter Address if(Ofc && Mob && Eml && FbkA && CampOff && OffAdr && Phn && FX && CampWeb) { line1 = Ofc; line2 = Mob; line3 = Eml; line4 = FbkG + FbkA; line5 = ""; line6 = CampOff; line7 = OffAdr; line8 = Phn; line9 = Fax; line10 = CampWeb; line11 = ""; } else // no Facebook Address if(Ofc && Mob && Eml && TwitA && CampOff && OffAdr && Phn && FX && CampWeb) { line1 = Ofc; line2 = Mob; line3 = Eml; line4 = TwitG + TwitA; line5 = ""; line6 = CampOff; line7 = OffAdr; line8 = Phn; line9 = Fax; line10 = CampWeb; line11 = ""; } else // no TwitA & no FaceBkadr if(Ofc && Mob && Eml && CampOff && OffAdr && Phn && FX && CampWeb) { line1 = Ofc; line2 = Mob; line3 = Eml; line4 = ""; line5 = CampOff; line6 = OffAdr; line7 = Phn; line8 = Fax; line9 = CampWeb; line10 = ""; line11 = ""; } else // no Mobile & no Twitter if(Ofc && Eml && FbkA && CampOff && OffAdr && Phn && FX && CampWeb) { line1 = Ofc; line2 = Eml; line3 = FbkG + FbkA; line4 = ""; line5 = CampOff; line6 = OffAdr; line7 = Phn; line8 = Fax; line9 = CampWeb; line10 = ""; line11 = ""; } else // no Mobile & no Facebook if(Ofc && Eml && TwitA && CampOff && OffAdr && Phn && FX && CampWeb) { line1 = Ofc; line2 = Eml; line3 = TwitG + TwitA; line4 = ""; line5 = CampOff; line6 = OffAdr; line7 = Phn; line8 = Fax; line9 = CampWeb; line10 = ""; line11 = ""; } else //no Mobile & No Twitter & No Facebook if(Ofc && Eml && CampOff && OffAdr && Phn && FX && CampWeb) { line1 = Ofc; line2 = Eml; line3 = ""; line4 = CampOff; line5 = OffAdr; line6 = Phn; line7 = Fax; line8 = CampWeb; line9 = ""; line10 = ""; line11 = ""; } else // no phone if(Ofc && Mob && Eml && TwitA && FbkA && CampOff && OffAdr && FX && CampWeb) { line1 = Ofc; line2 = Mob; line3 = Eml; line4 = TwitG + TwitA; line5 = FbkG + FbkA; line6 = ""; line7 = CampOff; line8 = OffAdr; line9 = Fax; line10 = CampWeb; line11 = ""; } else // no fax if(Ofc && Mob && Eml && TwitA && FbkA && CampOff && OffAdr && Phn && CampWeb) { line1 = Ofc; line2 = Mob; line3 = Eml; line4 = TwitG + TwitA; line5 = FbkG + FbkA; line6 = ""; line7 = CampOff; line8 = OffAdr; line9 = Phn; line10 = Fax; line11 = CampWeb; } else //nothing is missing line1 = Ofc; line2 = Mob; line3 = Eml; line4 = TwitG + TwitA; line5 = FbkG + FbkA; line6 = ""; line7 = CampOff; line8 = OffAdr; line9 = Phn; line10 = Fax; line11 = CampWeb; } } var result = line1; if (line2 + line3 + line4 + line5 + line6 + line7 + line8 + line9 + line10 + line11) result += "<br>\n" + line2 + "<br>\n"+ line3 + "<br>\n"+ line4 + "<br>\n" + line5 +"<br>\n" + line6 +"<br>\n" + line7 +"<br>\n" + line8 +"<br>\n" + line9 +"<br>\n" + line10 +"<br>\n" + line11; return result; Link to comment Share on other sites More sharing options...
esmith Posted May 13, 2010 Share Posted May 13, 2010 I admit my eyes glossed over by around the 25th line of your code. Assuming your fields are named similar to your initial vars at the beginning of your code, I would try something like this: // edit field names if necessary to match your data var info1 = Field("Office"); var info2 = Field("Mobile"); var info3 = Field("Email"); var info4 = Field("Twitter"); var info5 = Field("TwitAdr"); var info6 = Field("FaceBook"); var info7 = Field("FaceBkAdr"); var info8 = Field("CampusOffice"); var info9 = Field("OfficeAddress"); var info10 = Field("Phone"); var info11 = Field("Fax"); var info12 = Field("CampusWebsite"); // do not edit below this comment var cardInfo = []; var result = ""; // build an array of the populated fields in your record for (var i=1 i<=12; i++) { var element = "info" + i; if (element != "") cardInfo.push(element); } // build your return value from the array of data for (var k=0; k<cardInfo.length; k++) { result += cardInfo[k] + "<br>"; } // remove the trailing break tag result = Left(result, result.length-4); return result; Link to comment Share on other sites More sharing options...
JulieP Posted May 13, 2010 Author Share Posted May 13, 2010 Thanks! I knew there was a much better way just didn't know how to get there. Link to comment Share on other sites More sharing options...
Dan Korn Posted May 13, 2010 Share Posted May 13, 2010 You don't need to write any JavaScript code to do this. You can do it all in the Variable Text Editor for the text frame you want the data to appear in. Simply use the "Variable" drop-down and the "Insert" button to enter each data field or rule name on its own line (hitting Enter/Return to break up the lines). Then do a Select-All (Ctrl-A on Windows or Command-A on Mac) and click the "Paragraph" button, then click the box marked "Suppress if." Click OK twice and you're good to go. P.S. Eric, if you were going to do this in code, you're on the right track, but that's not quite right. A statement such as var element = "info" + i;is simply going to resolve to a string literal with a value of "info1" or "info2", etc., not the value of a variable with that name. There is a way to make that kind of code work, but as I said, this problem doesn't require any coding at all to solve. Link to comment Share on other sites More sharing options...
Dan Korn Posted May 13, 2010 Share Posted May 13, 2010 P.S. Eric, if you were going to do this in code, you're on the right track, but that's not quite right. A statement such as var element = "info" + i;is simply going to resolve to a string literal with a value of "info1" or "info2", etc., not the value of a variable with that name. There is a way to make that kind of code work, but as I said, this problem doesn't require any coding at all to solve. So again, you don't need any code at all to do this, but just as a fun exercise, if you were you do this in JavaScript, this is probably the most succinct solution: // Enter all the fields, rules, etc., that you want to output // one per line, skipping empty lines, here: var MyFields = [ Rule("OFFICERemoveWriteRule"), Rule("MOBILERemoveWriteRule"), Rule("EMAILRemoveWriteRule"), Rule("SuppressTwitGraph"), Rule("twitadrRemoveWriteRule"), Rule("Suppress Facebk graphic"), Rule("facebkadrRemoveWriteRule"), Rule("CampusOfficeRemoveWriteRule"), Rule("OfficeAdrRemoveWriteRule"), Rule("PHONERemoveWriteRule"), Rule("FAXRemoveWriteRule"), Rule("WEBSITERemoveWriteRule"), ]; // Don't edit below here: var NonEmptyFields = []; for(var i = 0; i < MyFields.length; i++) if(MyFields[i]) NonEmptyFields.push(MyFields[i]); return NonEmptyFields.join("<br>"); Link to comment Share on other sites More sharing options...
JulieP Posted May 13, 2010 Author Share Posted May 13, 2010 Thanks Dan! I think I will have to use JS because I am also dealing with 2 graphic icons that need to follow my lines of text. I have one line with a twitter graphic and text address and one with a Facebook graphic and test address. So, thank you so very much for the script! Link to comment Share on other sites More sharing options...
JulieP Posted May 14, 2010 Author Share Posted May 14, 2010 Hi Again Dan, Don't take this the wrong way but I thought you would like to know that I tried your code and it returned blank lines but the lines did not move up. I will try the alternate solution in the morning. I want you to know I really do appreciate your time and assistance greatly! This is what I am working on. They want each line to move up from the bottom when one is blank but they also want to maintain the same space between the top section and bottom section. http://www.crossmediamgmt.com/newbc.jpg Link to comment Share on other sites More sharing options...
JulieP Posted May 14, 2010 Author Share Posted May 14, 2010 Below is my code for suppressing the icon graphic for the twitter address. Would a possible solution be to first find the current x,y of my twitadr variable and then place the icon graphic (twitter) next to the twitadr variable? This is all I really need to do. All the text works correctly. I just need to move the graphics with the text. var TwitGraphic = CreateResource(Field("twitter"), "graphic", true); if(Field("twitadr") == "") { return NullResource; } else return Resource("twitter.pdf"); This is what currently happens if the office number is blank: http://www.crossmediamgmt.com/currentresults.jpg Link to comment Share on other sites More sharing options...
esmith Posted May 14, 2010 Share Posted May 14, 2010 You should be incorporating your graphic in the text frame as an inline graphic rather than in a separate graphic frame. Do a search in the forums for "inline graphic" for a slew of posts on how to do this. Link to comment Share on other sites More sharing options...
JulieP Posted May 14, 2010 Author Share Posted May 14, 2010 Fantastic! Will do. Thanks for the heads up! Julie Link to comment Share on other sites More sharing options...
JulieP Posted May 14, 2010 Author Share Posted May 14, 2010 The inline graphic works great. However, I need to tweak how it aligns with the text. Is there some way to force the text to align with the center of the graphic? I have tried everything I know to try in the text and Resource Editors and I couldn't find anything in the forums. And, THANKS TO EVERYONE FOR ALL THE HELP:) I have this: http://www.crossmediamgmt.com/ihavethis.jpg I need this: http://www.crossmediamgmt.com/ineedthis.jpg Link to comment Share on other sites More sharing options...
Dan Korn Posted May 14, 2010 Share Posted May 14, 2010 Sorry, you didn't mention anything at all in your initial post about trying to move graphics as well as text, so I had no way of knowing about that. Eric is right on that you need to be using inline graphics which flow with the text, rather than separate graphic frames. (Although you could build a table, but that's more complicated.) Now, you do need JavaScript rules to invoke the inline graphics. However, once you create the inline graphic rules, you can still apply them in the Text Editor and use the "Suppress if containing empty variables" setting to suppress the entire line, including the inline graphic, if the field value is empty. In other words, you still don't need any JavaScript logic to suppress the lines. You can see an example of this in the Cell Phone tutorial job that's installed with FP Desktop. Double-click on the frame on the middle of the first page and edit the text to insert the "signature" rule on the line with the "Add2" variable. http://forums.printable.com/attachment.php?attachmentid=253&d=1273862123 Then, with that same line selected, click "Paragraph..." and change the setting in the "Suppress if" drop-down list to "Containing empty variables." http://forums.printable.com/attachment.php?attachmentid=254&stc=1&d=1273862334 Then click OK twice to exit the Text Editor. Open the Preview Record Selector and check the "Preview" box. For record 1, you won't see the signature because the "Add2" field is empty. Now click the forward arrow button on the Preview palette and you'll see that for record 2, the signature appears on the line with the "Add2" field value. Every record with an "Add2" line will show it along with the graphic, and every record without an "Add2" line will suppress the graphic. Cool, huh? This is exactly what you want to do in your job. You may have to tweak the inline graphic rule to get the graphic to appear at the proper size, but once you do that, suppressing the line containing is as easy as a few clicks. Link to comment Share on other sites More sharing options...
Dan Korn Posted May 14, 2010 Share Posted May 14, 2010 The inline graphic works great. However, I need to tweak how it aligns with the text. Is there some way to force the text to align with the center of the graphic? I have tried everything I know to try in the text and Resource Editors and I couldn't find anything in the forums. And, THANKS TO EVERYONE FOR ALL THE HELP:) I have this: http://www.crossmediamgmt.com/ihavethis.jpg I need this: http://www.crossmediamgmt.com/ineedthis.jpg Sorry, I didn't see your other reply before I typed up my last one. Obviously you figured out how to make the inline graphic. This is now getting into a separate question, which is not so much about suppressing lines as it is about aligning inline graphics with text. Tweaking that is a little more complicated. Basically, everything on the line, including inline graphics, lines up to the baseline for the text. If the graphics are larger than the text, they will always have the kind of effect like you're seeing, by default. That said, it looks like your graphics are actually sitting a little bit above the baseline. Without seeing the graphics themselves, I can't really tell for sure, but I suspect this is because the images have some white space padding around them. You could try editing the images to crop off the white space and see if that helps. However, if the graphics are larger than the text, you'll still see them on the baseline, not centered as you're trying to do. There are a few things you can do to tweak the output to look different than the defaults. One is to make a table and place the graphic and the text in adjacent cells on the same row. This approach will give you the most fine-grain control, but it's also the most complicated to do. You may also be able to use a Repeatable Component (Template Page), but that's pretty complex too. Short of creating a table or Repeatable Component , there are a couple of relatively simple things you can do, in your inline graphic rule. The first is to tweak the size of the inline graphic with the height and/or width attributes of the graphic tag. For instance: return "<graphic file=signature.jpg height=1000>"; You'll have to play around with the numbers to get the desired effect, and you still may need to remove whitespace from the graphics themselves. Another option is to put the text in superscript, raising it above the baseline, like so: return "<graphic file=signature.jpg><p br=false superratio=100 superoffset=30><superscript>";Again, you'll have to tweak the offset here, and this will also change the baseline relative to other lines, which may not be what you want either. You may be able to work around this by putting ALL the text in superscript, although at that point you're getting into the area where you might as well make a table. But it's something to try. Link to comment Share on other sites More sharing options...
JulieP Posted May 14, 2010 Author Share Posted May 14, 2010 Thanks Dan! You are the best! I will work on it and try to achieve a better look. Thanks again for all your help! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.