Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 31st, 2017, 08:08 AM
gdellaiera gdellaiera is offline
Regular Contributor
 
Join Date: Nov 2016
Posts: 78
Default 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);
}
Reply With Quote
  #2  
Old July 31st, 2017, 10:50 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,366
Default Re: On Record Start

It seems to me that this part of the rule has absolutely no effect:
Quote:
Originally Posted by gdellaiera View Post
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 View Post
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.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #3  
Old July 31st, 2017, 12:33 PM
gdellaiera gdellaiera is offline
Regular Contributor
 
Join Date: Nov 2016
Posts: 78
Default 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
Reply With Quote
  #4  
Old July 31st, 2017, 01:37 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,366
Default Re: On Record Start

Okay, I think the key word in your description of the requirement is "OR".
Quote:
Originally Posted by gdellaiera View Post
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.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; July 31st, 2017 at 02:44 PM.. Reason: fixed typo
Reply With Quote
  #5  
Old July 31st, 2017, 01:51 PM
gdellaiera gdellaiera is offline
Regular Contributor
 
Join Date: Nov 2016
Posts: 78
Default 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
Reply With Quote
  #6  
Old July 31st, 2017, 02:46 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,366
Default Re: On Record Start

Quote:
Originally Posted by gdellaiera View Post
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);
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #7  
Old July 31st, 2017, 03:29 PM
gdellaiera gdellaiera is offline
Regular Contributor
 
Join Date: Nov 2016
Posts: 78
Default 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!
Reply With Quote
  #8  
Old July 31st, 2017, 06:48 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,366
Default Re: On Record Start

Quote:
Originally Posted by gdellaiera View Post
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";
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #9  
Old August 1st, 2017, 06:47 AM
gdellaiera gdellaiera is offline
Regular Contributor
 
Join Date: Nov 2016
Posts: 78
Default 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?
Reply With Quote
  #10  
Old August 1st, 2017, 10:27 AM
GreggRusson GreggRusson is offline
Junior Community Member
 
Join Date: May 2011
Location: Seattle
Posts: 35
Default 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.
Reply With Quote
Reply

Tags
fusionpro, javascript, onrecordstart

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:03 AM.


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