MarcomCentral (PTI) and FusionPro User Communities

MarcomCentral (PTI) and FusionPro User Communities (http://forums.pti.com/index.php)
-   The JavaScript Library (http://forums.pti.com/forumdisplay.php?f=23)
-   -   On Record Start (http://forums.pti.com/showthread.php?t=4944)

gdellaiera July 31st, 2017 08:08 AM

On Record Start
 
So I was able to come up with a good rule for On Record Start for a Name/Title field, but then had to add in a condition for the address as well. It worked perfectly fine until I added the address portion & now it will only use the 'long page', even when the 'short page' is supposed to be used.

Is there something missing below? I've been racking my brain to figure out what is going on, but every time I validate, FusionPro returns 'Expressions Ok'.

Thanks for the look.

var name = Field("Name");

var title = Field("Title");

var nametitle = name + "," + title;

if (nametitle.length <= 26){
FusionPro.Composition.SetBodyPageUsage("Short Name", true);
FusionPro.Composition.SetBodyPageUsage("Long Name", false);
}
else{
FusionPro.Composition.SetBodyPageUsage("Short Name", false);
FusionPro.Composition.SetBodyPageUsage("Long Name", true);
};

var address = Rule("Format Address");

if (address.length <= 40){
FusionPro.Composition.SetBodyPageUsage("Short Name", true);
FusionPro.Composition.SetBodyPageUsage("Long Name", false);
}
else{
FusionPro.Composition.SetBodyPageUsage("Short Name", false);
FusionPro.Composition.SetBodyPageUsage("Long Name", true);
}

Dan Korn July 31st, 2017 10:50 AM

Re: On Record Start
 
It seems to me that this part of the rule has absolutely no effect:
Quote:

Originally Posted by gdellaiera (Post 20320)
var name = Field("Name");

var title = Field("Title");

var nametitle = name + "," + title;

if (nametitle.length <= 26){
FusionPro.Composition.SetBodyPageUsage("Short Name", true);
FusionPro.Composition.SetBodyPageUsage("Long Name", false);
}
else{
FusionPro.Composition.SetBodyPageUsage("Short Name", false);
FusionPro.Composition.SetBodyPageUsage("Long Name", true);
};

Because, regardless of what page usage was set above based on the name and title, you're completely resetting the page usage based on the address:
Quote:

Originally Posted by gdellaiera (Post 20320)
var address = Rule("Format Address");

if (address.length <= 40){
FusionPro.Composition.SetBodyPageUsage("Short Name", true);
FusionPro.Composition.SetBodyPageUsage("Long Name", false);
}
else{
FusionPro.Composition.SetBodyPageUsage("Short Name", false);
FusionPro.Composition.SetBodyPageUsage("Long Name", true);
}

It's not clear exactly what should happen if, say, the name and title are longer than 27 characters but the address is less than 40 characters.

Although, in 99 out of 100 cases like this, you can usually implement some other way of accomplishing the results you need without creating entirely new sets of pages for variable text of different lengths. The most common way to resolve something like this is via copyfitting, either full-flow copyfitting (by checking the "Adjust text to fit" box on the Overflow Options dialog), or per-line copyfitting (by using the CopyfitLine or similar text measurement in a rule. Other strategies including having multiple (sets of) frames and selectively suppressing them, resizing frames, and using tables. If I could see the job files, or at least the desired output, I might be able to offer a more specific suggestion.

Also, the reason you get "Expressions OK" is because, well, the expressions are okay. If you want to return something from the rule just to see what's happening, you can certainly do that, but, as the message will then say, the return value will have no effect on the composition.

gdellaiera July 31st, 2017 12:33 PM

Re: On Record Start
 
Dan,

Unfortunately I am not able to load the file or the zip right now. I will keep trying.

As for the desired affect; If the name + title > 26 characters and/or the Address is > 40 characters, the initial page with graphic frames is to be forgone & the second page with no graphic frames is to be used (as it has larger text frames).

This is due to the fact that fonts cannot be smaller than they already are (which is why I cannot use any sort of copy fitting or resizing rules).

I don't know if this clears anything up for you

Dan Korn July 31st, 2017 01:37 PM

Re: On Record Start
 
Okay, I think the key word in your description of the requirement is "OR".
Quote:

Originally Posted by gdellaiera (Post 20325)
As for the desired affect; If the name + title > 26 characters and/or the Address is > 40 characters, the initial page with graphic frames is to be forgone & the second page with no graphic frames is to be used (as it has larger text frames).

So that should be an "OR" (denoted by "||") in your rule:
Code:

var address = Rule("Format Address");
var name = Field("Name");
var title = Field("Title");
var nametitle = name + "," + title;

if (nametitle.length > 26 || address.length > 40)
{
    FusionPro.Composition.SetBodyPageUsage("Short Name", false);
    FusionPro.Composition.SetBodyPageUsage("Long Name", true);
    return "using long names";
}
else
{
    FusionPro.Composition.SetBodyPageUsage("Short Name", true);
    FusionPro.Composition.SetBodyPageUsage("Long Name", false);
    return "using short names";
}

Or, equivalently:
Code:

var address = Rule("Format Address");
var nametitle = Field("Name") + "," + Field("Title");
var needLongText = (nametitle.length > 26 || address.length > 40);
FusionPro.Composition.SetBodyPageUsage("Short Name", !needLongText);
FusionPro.Composition.SetBodyPageUsage("Long Name", needLongText);
return "using " + (needLongText  ? "long" : "short") + " names";

It is also still true that, instead of suppressing pages selectively, you could accomplish this by having multiple sets of named frames on the same page, and suppressing frames selectively, or by resizing frames if you're composing via FP Server or Producer.

gdellaiera July 31st, 2017 01:51 PM

Re: On Record Start
 
OK the or was definitely confusing me. I am however getting a syntax error with both rules.

Line 6, (the first vertical bar is highlighted |) Syntax error: syntax error is what is read.

This rule makes sense to use, but even after retyping it, I am still getting an error

Dan Korn July 31st, 2017 02:46 PM

Re: On Record Start
 
Quote:

Originally Posted by gdellaiera (Post 20327)
OK the or was definitely confusing me. I am however getting a syntax error with both rules.

Line 6, (the first vertical bar is highlighted |) Syntax error: syntax error is what is read.

This rule makes sense to use, but even after retyping it, I am still getting an error

Sorry, I had an extra parend in there. That line should be:
Code:

if (nametitle.length > 26 || address.length > 40)
or in the second example:
Code:

var needLongText = (nametitle.length > 26 || address.length > 40);

gdellaiera July 31st, 2017 03:29 PM

Re: On Record Start
 
Thanks Dan, I think that is working. I cannot preview or see anything in the composition file, but I believe that means that all is good!

Dan Korn July 31st, 2017 06:48 PM

Re: On Record Start
 
Quote:

Originally Posted by gdellaiera (Post 20329)
Thanks Dan, I think that is working. I cannot preview or see anything in the composition file, but I believe that means that all is good!

Great! Yes, if you suppress an entire page, then you won't see any content in its frames when you Preview, and that page will of course not be present at all in composed output. (Though if you use a different strategy, such as suppressing frames instead of entire pages, you will see a better representation of the composed output in Preview.)

I will leave you with one other thing to consider: Counting the number of characters is a very poor way to determine whether text is going to fit into a particular frame. Unless you're using a monospaced font, some letters are wider than others. A name with a lot of W's and M's is going to take up a lot more space than a name with a lot of I's and L's, even with the same number of characters. For instance, in the default font on this forum:
Quote:

Mayweather ->10 letters, but wider
Illivanovic -> 11 letters, but narrower
So what you really should do is measure the text, using the FusionProTextMeasure object, to see how much space it really takes up, and compare that to the actual width of the frame. For instance, you can name your frame(s) and do this:
Code:

var nametitle = Field("Name") + "," + Field("Title");
var address = Rule("Format Address");

var TM = new FusionProTextMeasure;
TM.font = "Arial"; // <- font you're using
TM.pointSize = 10; // <- text point size
TM.CalculateTextExtent(nametitle);
var nameFrame = FindTextFrame("Name"); // <- your frame name
var nameTitleTooBig = TM.textWidth > nameFrame.GetSettableTextWidth();

TM.font = "Arial"; // <- font you're using
TM.pointSize = 10; // <- text point size
TM.CalculateTextExtent(address);
var addressFrame = FindTextFrame("address"); // <- your frame name
var addressTooBig = TM.textWidth > addressFrame.GetSettableTextWidth();

var needLongText = nameTitleTooBig || addressTooBig;
FusionPro.Composition.SetBodyPageUsage("Short Name", !needLongText);
FusionPro.Composition.SetBodyPageUsage("Long Name", needLongText);
return "using " + (needLongText  ? "long" : "short") + " names";


gdellaiera August 1st, 2017 06:47 AM

Re: On Record Start
 
Dan, thanks for all the help. I was wondering though, how one would go about suppressing frames vs. suppressing pages. Obviously you would have multiple frames overlapping each other, but is there something in FusionPro (like an OnRecordStart rule) that does this? Or is it pure scripting?

GreggRusson August 1st, 2017 10:27 AM

Re: On Record Start
 
Look in the user manual for 'Modifying Frames During Composition'. This section will give you an overview of how to programmatically write (or add to ) a OnRecordStart rule to find and modify either a graphic or text frames properties. To find all the properties of a frame (of which suppress is one), consult the Rules system guide under the FusionProFrame Attributes section.


All times are GMT -7. The time now is 06:11 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.