ChuckBrodeur Posted October 21, 2014 Share Posted October 21, 2014 New to Javascript but I have to write a rule that returns a string in which part of the string will be arial narrow 6 pt and another part will be arial narrow bold 10pt. Not sure how to write that. What I have so far returns the font size calls as well as the string text. if(Field("***") !="3") { return <font size="6"."Size "</font> + <font size="10">Field("SIZE"),/font>; } else { return " "; } I expect it to end up looking like: Size 7 or something like that. I haven't even started on the attributes for bold and font name until i can figure this out. Thanks. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 21, 2014 Share Posted October 21, 2014 Those aren't valid markup tags for FusionPro. Just because FusionPro uses JavaScript as a scripting engine doesn't mean that you use the same markup tags that you would use in HTML. The way to change point size in FusionPro markup is with a tag such as <z newsize=10>. To change the font name, you need a tag like <f name="Arial">. Bold and italic styles are requested with <b> and <i> tags. Please refer to the FusionPro Tags Reference manual for more information. Here's a handy trick to be able to see what tagging FusionPro uses: Open the Resources dialog, click Add, select "Formatted Text" in the Type drop-down, click Edit, type some text, select whatever formatting you want with the controls, or in the Paragraph Formatting dialog, then click OK in the Text Editor dialog, and back in the Resource Editor dialog, click "View Source." This will show you all of the markup that corresponds to the selections you made in the GUI. Also, if you're trying to output a data field value with some tagging, your JavaScript syntax is wrong. You need to do something like this: return '<z newsize="6">Size <z newsize="10">' + Field("SIZE"); Note that you need to end the running literal text string with the tags with an ending quote, then append the Field function call with a plus sign. Quote Link to comment Share on other sites More sharing options...
ChuckBrodeur Posted October 22, 2014 Author Share Posted October 22, 2014 I tried changing my return line to look like this: return '<f name="Arial Narrow">',"Size ",'</f>' + '<z newsize="10"><b>',Field("Size"),'</b>'; But the value returned when I click the validate button is </b>. I have tried it without the quotation marks and without the commas, but keep getting syntax errors saying I am "missing ; before the statement". When I put in ; where the gray is showing in my script then validation only returns <f name="Arial Narrow">. Not sure what to do next, I can't find in the guide doesn't where it covers this. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 22, 2014 Share Posted October 22, 2014 (edited) I tried changing my return line to look like this: return '<f name="Arial Narrow">',"Size ",'</f>' + '<z newsize="10"><b>',Field("Size"),'</b>'; But the value returned when I click the validate button is </b>. I have tried it without the quotation marks and without the commas, but keep getting syntax errors saying I am "missing ; before the statement". When I put in ; where the gray is showing in my script then validation only returns <f name="Arial Narrow">. Not sure what to do next, I can't find in the guide doesn't where it covers this. This is no longer an issue of getting the FusionPro markup tags right; it's an issue of your JavaScript syntax. It looks like you're trying to use commas to concatenate strings together, but the actual string concatenation operator in JavaScript is + (the plus sign). So you need to replace those commas with plus signs, like so: return '<f name="Arial Narrow">' + "Size " + '</f>' + '<z newsize="10"><b>' + Field("Size") + '</b>'; Although most of the plus signs between string literals can be removed by simply combining those literals: return '<f name="Arial Narrow">Size </f><z newsize="10"><b>' + Field("Size") + '</b>'; And there is actually one other possibility, although you'll only see the actual field value when you compose, not when you click Validate: return '<f name="Arial Narrow">Size </f><z newsize="10"><b><variable name="Size"></b>'; Edited October 22, 2014 by Dan Korn added <variable> tag example Quote Link to comment Share on other sites More sharing options...
ChuckBrodeur Posted October 22, 2014 Author Share Posted October 22, 2014 This is still not working, if I put the +'s in then I get the whole string printing out including the font tags. Sorry this is so rudimentary, but if I write the line like this: return "Size " + Field("Size"); It prints correctly (Size 7, for example). But the second I try to tag it to make the 7 bigger and bold is when I get into my problem. From reading the tag guide and looking at your examples the code you wrote should work. Should I be using a different operator other than return? Does it make a difference that I am using FusionPro VDP Producer (API) 9.3.5 on a pc running XP SP3? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 22, 2014 Share Posted October 22, 2014 This is still not working, if I put the +'s in then I get the whole string printing out including the font tags. You need to check the "Treat returned strings as tagged text" box, near the top of the Rule Editor dialog. Technically, when you do that, you should account for markup-like characters in the data as well, by using the TaggedTextFromRaw or TaggedDataField functions. So the ultimate solution is to check that box, and do this: return '<f name="Arial Narrow">Size </f><z newsize="10"><b>' + TaggedDataField("Size") + '</b>'; Quote Link to comment Share on other sites More sharing options...
ChuckBrodeur Posted October 22, 2014 Author Share Posted October 22, 2014 That seemed to work when I do the preview template but the validation window still shows the string of code so it was confusing and making me think it wasn't working. Thanks for all your help on this! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.