Jump to content

First Try with Tagged Text


bkurzbuch

Recommended Posts

JavaScript Newbie

 

 

This is my first attempt using tagged text. There is a problem with my code, but I don't have the JavaScript knowledge to understand what the error is. Code is below.

 

 

Trying to "If value of UA Plus Individual is greater than 1 return line of text "Individual: $<UA Plus Individual> per <Pay Period> otherwise return nothing."

 

 

I get a error Line 8 Syntax Error: unexpected end of XML source.

Any advise or help would be greatly appreciated. Thank You.

 

 

 

 

 

 

if (Field("UA Plus Individual") > "1")

{

return <p style="(no style)" br="false" override="true" quad="L" findent="0" lindent="0" rindent="0" leadbefore="0" leadafter="0" keeplines="true" widows="2"

kerning="true" hyphenate="false" skipifempty="false" skipifemptyvar="false" noparabreakoncopyfit="false"><tracking newsize="0">

<f name="TisaSansOT-Medium"><z newsize="8.0"><color name="Black">Individual:<f name="TisaSansOT-Light"> $<variable name="UA Plus Individual"> per

<variable name="Pay Period"><t>;

}

return "";

Link to comment
Share on other sites

That looks like you pulled that code directly out of a text resource. Most of that isn't necessary for what you're trying to return. The paragraph tags, tracking, font, etc is the way that FusionPro marks up the text that you've set in your text editor so if you're adding that into the same text box with the same settings (font, tracking, etc) then all of that code really becomes redundant.

 

The other issue is that the "<variable name=.." tags are also the way that FP markups up your text editor input. If you really want to use the tagged text, you can replace those with your fields like this (note that tags need to be treated as strings i.e. in quotes):

if (Field("UA Plus Individual") > "1")
{
return '<p style="(no style)" br="false" override="true" quad="L" findent="0" lindent="0" rindent="0" leadbefore="0" leadafter="0" keeplines="true" widows="2" kerning="true" hyphenate="false" skipifempty="false" skipifemptyvar="false" noparabreakoncopyfit="false"><tracking newsize="0"><f name="TisaSansOT-Medium"><z newsize="8.0"><color name="Black">Individual:<f name="TisaSansOT-Light"> $' + Field("UA Plus Individual") + '> per' + Field("Pay Period") + '<t>';
}
return "";

 

I think you'd be better off doing something like this though:

if (Field("UA Plus Individual") > "1")
{
return '<f name="TisaSansOT-Medium">Individual:<f name="TisaSansOT-Light"> $' + Field("UA Plus Individual") + '> per' + Field("Pay Period") + '<t>';
}
return "";

 

Or more succinctly:

var result = '<f name="TisaSansOT-Medium">Individual:<f name="TisaSansOT-Light"> $' + Field("UA Plus Individual") + '> per' + Field("Pay Period") + '<t>';
return (Field("UA Plus Individual") > "1") ? result : "";

 

Out of curiosity because it seems like you're working on the same problem, did the solution I posted here not work for you?

Link to comment
Share on other sites

Hi Ste

 

Yes it did. Have some down time and trying to learn more about JavaScript and different ways around the same problem. Thanks for you help. Always greatly appreceatied.

 

Do you have a good book or online source for learning JavaScript. It seems so simple yet extremely powerful in what it can do. Trying to get a good knowledge of the language and syntax is a little overwhelming. Thanks Again for your help, have a good weekend.

 

P.S. You are correct. i did pull the text out of the text resource.

Edited by bkurzbuch
Link to comment
Share on other sites

To be quite honest, I have learned so much about JavaScript through this forum. Users like Dan, Eric, and countless others have given some pretty clever solutions to issues I would have never come up with on my own.

 

I don't know of any one book per se that I would recommend as a "read this and you'll master JS," but I frequently visit W3Schools and CodeAcademy for definitions, examples, terminology, and the like.

 

It's important to keep in mind that most things you'll find on the internet will be JavaScript and how it relates to websites but much of that knowledge can be applied to the way FusionPro uses the language. FP also has certain "FP-specific" functions, objects, etc that won't show up on any website outside of the FP community but their uses and functionality are pretty well documented in their documentation and on this forum.

 

My strongest suggestion would be to search this forum for solutions, ask questions, and try to understand what's happening in solutions that are offered. Inquire about how code works if you don't get it. I'd also highly recommend participating. Try to offer solutions to problems that challenge you because you'll either teach someone something or teach yourself a new way of doing something.

 

Good luck!

Link to comment
Share on other sites

I get a error Line 8 Syntax Error: unexpected end of XML source.

The reason you're getting that particular error message is that you need to use quotes to build up string literals in JavaScript. You can just start making tags with angle brackets without putting quotes around them. The easiest way to do this is to simply use single quotes around that whole mess of tags. But Step is right; you don't really need all of that markup.

 

In fact, I'm not sure why you are using tagged markup at all to accomplish this stated requirement:

Trying to "If value of UA Plus Individual is greater than 1 return line of text "Individual: $<UA Plus Individual> per <Pay Period> otherwise return nothing."

You don't mention anything in there about needing to set any font or other formatting to the text, so therefore there's no need to use markup. So your pseudo code requirement translates to this much simpler bit of JavaScript:

if (Int(Field("UA Plus Individual")) > 1)
   return 'Individual: $' + Field("UA Plus Individual") + ' per ' + Field("Pay Period");
// else
return "";

You can simply set the font in the Text Editor where you call out this rule.

 

(Note also that my solution uses the Int function to compare the field value to the number 1 numerically. Comparing the field value as a string to the string value "1" textually can give you unexpected results.)

 

If you really do want to modify the formatting of the text you're conditionally returning, you can still do that without using any markup tags at all. Simply create a Formatted Text Resource, and set all the formatting you want in there, and then you rule can just do this:

if (Int(Field("UA Plus Individual")) > 1)
   return Resource("UA Plus Ind"); // whatever name you give the resource
// else
return "";

No tagging required!

Link to comment
Share on other sites

If you really do want to modify the formatting of the text you're conditionally returning, you can still do that without using any markup tags at all. Simply create a Formatted Text Resource, and set all the formatting you want in there, and then you rule can just do this:

if (Int(Field("UA Plus Individual")) > 1)
   return Resource("UA Plus Ind"); // whatever name you give the resource
// else
return "";

No tagging required!

Actually, you can do this without any JavaScript at all. Just create your Formatted Text Resource, then make a new Drag-and-Drop Wizard rule, and set the first drop-down to "Numeric value of", drag in your data field, set the next drop-down to "is greater than", type in the number 1, and in the "Then Return" line, drag in the resource. That's it!

 

I certainly don't mean to discourage you from learning about tagged markup and JavaScript, but users often don't realize how much can be done without needing any of that at all.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...