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, 04:22 PM
NAFPRm's Avatar
NAFPRm NAFPRm is offline
Forum n00b
 
Join Date: Dec 2015
Location: Orange County, CA
Posts: 6
Default OnRecordStart - applying to multiple pages

I have a 12-page project (a booklet) where many of the VDP fields we use are repeated on multiple pages.

We have the OnRecordStart code below in place. The second part is a code that basically says "show the company name as text unless a logo is available in which case hide the text and show the logo". It works perfectly for the first such appearance of this code, but in all other appearances it doesn't work and displays the logo and text simultaneously.

How can I make it apply to the whole project?

Code:
var Name = Field("REA_FirstName")
var Headshot = Field("REA_Headshot")
var Logo = Field("REA_Logo")

if(Name =="" || Headshot =="")
{
FindTextFrame("REA..TXT..Data").suppress=true;
FindTextFrame("REA..TXT..Message").suppress=true;
FindGraphicFrame("REA..IMG..Headshot").suppress=true;
FindGraphicFrame("REA..IMG..CompanyLogo").suppress=true;
FindTextFrame("REA..TXT..CompanyName").suppress=true;
}

if(Logo !="")
{
FindTextFrame("REA..TXT..CompanyName").suppress=true;
}
Reply With Quote
  #2  
Old July 31st, 2017, 06:30 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,592
Default Re: OnRecordStart - applying to multiple pages

Quote:
Originally Posted by NAFPRm View Post
I have a 12-page project (a booklet) where many of the VDP fields we use are repeated on multiple pages.

We have the OnRecordStart code below in place. The second part is a code that basically says "show the company name as text unless a logo is available in which case hide the text and show the logo". It works perfectly for the first such appearance of this code, but in all other appearances it doesn't work and displays the logo and text simultaneously.

How can I make it apply to the whole project?
You can't have multiple frames with the same name, even on different Body pages. Well, you can, but the FindTextFrame and FindGraphicFrame functions are only going to find one of the frames with the given name.

I think you need a different approach to this template. There are several options, though which one is best for your template is hard to say without knowing more about it.

One thing you can do is to give all of the frames different names on different pages, in some kind of pattern, like with the page name, so that you have frames named "REA..TXT..Data_1", "REA..TXT..Data_2", "REA..TXT..Data_3", etc., and so on for all the other frames. Then you can suppress all of them in a loop, like so:
Code:
var Name = Field("REA_FirstName");
var Headshot = Field("REA_Headshot");
var Logo = Field("REA_Logo");

for (var i = 1; i <= 12; i++)
{
    if (Name == "" || Headshot == "")
    {
        FindTextFrame("REA..TXT..Data_" + i).suppress=true;
        FindTextFrame("REA..TXT..Message_" + i).suppress=true;
        FindGraphicFrame("REA..IMG..Headshot_" + i).suppress=true;
        FindGraphicFrame("REA..IMG..CompanyLogo_" + i).suppress=true;
        FindTextFrame("REA..TXT..CompanyName_" + i).suppress=true;
    }

    if (Logo != "")
    {
        FindTextFrame("REA..TXT..CompanyName_" + i).suppress=true;
    }
}
Another option is to simply insert a rule into each of the frames which returns either empty text or some other content (for a text frame) or a graphic or NullResource() (for a graphic frame). In other words, instead of suppressing the frames, you can just set them to have no content. A rule might look something like this:
Code:
// Graphic rule "Headshot"
var Name = Field("REA_FirstName")
var Headshot = Field("REA_Headshot");

if (Name == "" || Headshot == "")
   return NullResource();
//else
// ...whatever else your rule for the "REA..IMG..Headshot" frame was doing...
However, you still need to make multiple rules, and then modify every copy of the frame on every page any time to do that. And you may need to modify every copy of every frame again later if you need to change anything else. That makes the whole template hard to maintain. A general rule of thumb I like to follow is that, if you are manually/painstakingly adding/modifying the same frames on multiple pages, then there's almost always a way to accomplish what you need without so much manual, repetitive work. After all, the whole reason you have a computer is to automate repetitive tasks, right?

One way to reduce the number of repetitive tasks and make the template more maintainable is to place all of the frames that are common into a Repeatable Component, or Template Page, or actually, into two or more Template pages, one for each variation of the layout, so that instead of suppressing particular frames, you call out the version of the Template page which has just the frames you want. You'll just have a single text frame on each Body page, which will call out a rule which instantiates and returns one of the Repeatable Components, something like this:
Code:
var Name = Field("REA_FirstName");
var Headshot = Field("REA_Headshot");
var Logo = Field("REA_Logo");

var rc = new FPRepeatableComponent("All");
if(Name == "" || Headshot == "")
{
  rc = new FPRepeatableComponent("NoHeadshot");
}
else if (Logo != "")
{
  rc = new FPRepeatableComponent("NoCompany");
}
return rc;
Another option may be simply to repeat the entire record, which will effectively repeat each page the same number of times. All you need is this in OnRecordStart:
Code:
FusionPro.Composition.repeatRecordCount = 12;
If you need to do something else specific to each repeat (like in all the other frames that don't have the same content on all 12 pages), you can use the FusionPro.Composition.repeatRecordNumber property.

There may be other ways to approach the template and reduce both the number of pages and frames and the number of lines of code. But again, I would have to see the template, or at least know a bit more about it, to be able to make a more specific suggestion.
__________________
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 August 1st, 2017, 10:14 AM
NAFPRm's Avatar
NAFPRm NAFPRm is offline
Forum n00b
 
Join Date: Dec 2015
Location: Orange County, CA
Posts: 6
Default Re: OnRecordStart - applying to multiple pages

I think the first solution would work, but I get an error that says:
  • In FindFrame(), no frame named "REA..TXT..CompanyName_1"

I'm guessing this has to do with how I named the fields on each page. Because the same field can appear on a page I had to add identifiers to, so the naming system looks like this

"REA..TXT..CompanyName..P01a"

where "P01" represents "page 1" and "a" distinguishes it from others on the same page (for example the next one would be "REA..TXT..CompanyName..P01b", etc.)

using this system, is there a way to use your first code and make it work?
Reply With Quote
  #4  
Old August 1st, 2017, 01:35 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,592
Default Re: OnRecordStart - applying to multiple pages

Quote:
Originally Posted by NAFPRm View Post
I think the first solution would work, but I get an error that says:
  • In FindFrame(), no frame named "REA..TXT..CompanyName_1"

I'm guessing this has to do with how I named the fields on each page.
Well, yes, if you don't have a frame with that name, then you'll get that error.
Quote:
Originally Posted by NAFPRm View Post
Because the same field can appear on a page I had to add identifiers to, so the naming system looks like this

"REA..TXT..CompanyName..P01a"

where "P01" represents "page 1" and "a" distinguishes it from others on the same page (for example the next one would be "REA..TXT..CompanyName..P01b", etc.)

using this system, is there a way to use your first code and make it work?
So you have multiple copies of each frame on each of multiple pages? In other words, there's "REA..TXT..CompanyName..P01a", "REA..TXT..CompanyName..P01b" etc. on one page, and then "REA..TXT..CompanyName..P02a", "REA..TXT..CompanyName..P02b" on another page, and so on? This sounds like even more of a complicated set of manually-created frames than I originally thought. It also sounds like a nightmare to maintain. I'd really like to be able to take a look at the job and see if there's a better way to approach it.

Anyway, if you really want to go with that model, then sure, you could iterate over the frames on each page. One way would be to name them something like "REA..TXT..CompanyName..P01_1", "REA..TXT..CompanyName..P01_2", etc. But if you have the letters, you can do something like this:
Code:
var Name = Field("REA_FirstName");
var Headshot = Field("REA_Headshot");
var Logo = Field("REA_Logo");

for (var i = 1; i <= 12; i++)
{
    for (var k = Asc('a'); k <= Asc('d'); k++) // <- change 'd' to however many you need to iterate
    {
        var suffix = "..P" + FormatNumber("00", i) + Chr(k);
        if (Name == "" || Headshot == "")
        {
            FindTextFrame("REA..TXT..Data" + suffix).suppress=true;
            FindTextFrame("REA..TXT..Message" + suffix).suppress=true;
            FindGraphicFrame("REA..IMG..Headshot" + suffix).suppress=true;
            FindGraphicFrame("REA..IMG..CompanyLogo" + suffix).suppress=true;
            FindTextFrame("REA..TXT..CompanyName" + suffix).suppress=true;
        }

        if (Logo != "")
        {
            FindTextFrame("REA..TXT..CompanyName" + suffix).suppress=true;
        }
    }
}
Again, though, it's difficult to try to code this blind, without the template files.
__________________
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
  #5  
Old August 1st, 2017, 04:30 PM
NAFPRm's Avatar
NAFPRm NAFPRm is offline
Forum n00b
 
Join Date: Dec 2015
Location: Orange County, CA
Posts: 6
Default Re: OnRecordStart - applying to multiple pages

Quote:
This sounds like even more of a complicated set of manually-created frames than I originally thought. It also sounds like a nightmare to maintain.
haha, it is.

Yea, there are pages in the booklet where the same field - headshot for instance - will appear multiple times, however it isn't consistent. Some pages have several, some have no VDP fields at all.

I'm not committed to any solution. Whatever works, really. I tried the one you most recently provided and it didn't work. Same issue: solved the first appearance of the text/logo issue, but didn't work on any others.
Reply With Quote
  #6  
Old August 1st, 2017, 04: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,592
Default Re: OnRecordStart - applying to multiple pages

Quote:
Originally Posted by NAFPRm View Post
haha, it is.

Yea, there are pages in the booklet where the same field - headshot for instance - will appear multiple times, however it isn't consistent. Some pages have several, some have no VDP fields at all.

I'm not committed to any solution. Whatever works, really. I tried the one you most recently provided and it didn't work. Same issue: solved the first appearance of the text/logo issue, but didn't work on any others.
Well, feel free to post the job files here and take me up on my offer to look at them and try to come up with a better approach. Or not. You might also consider some custom template-building from our excellent Services team.
__________________
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 August 1st, 2017, 05:03 PM
NAFPRm's Avatar
NAFPRm NAFPRm is offline
Forum n00b
 
Join Date: Dec 2015
Location: Orange County, CA
Posts: 6
Default Re: OnRecordStart - applying to multiple pages

Please see attached...
Attached Files
File Type: pdf RK(Blank).pdf (527.5 KB, 8 views)
Reply With Quote
  #8  
Old August 1st, 2017, 06:06 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,592
Default Re: OnRecordStart - applying to multiple pages

Quote:
Originally Posted by NAFPRm View Post
Please see attached...
Thanks for posting the template. But I said to post the job fileS, plural. At an absolute minimum, I obviously also need a data file in order to try it out (run the rules, compose, etc.). An example of what you want the output to look like would be helpful as well.

That said, I noticed a few important details in the template:

For one thing, your naming convention is inconsistent. You have some of the frames with names like "REA..IMG..CompanyLogo..P01a", with a "P" before the page number and the letter, and others with names like "REA..IMG..CompanyLogo..09c", without the "P", and then others which don't match either pattern, such as "LO..IMG..Headshot..P01F1". In order to handle all of these in a loop like we're trying to do, the names absolutely need to be consistent, and follow the pattern exactly.

Mostly, though, I never intended that what I posted would just fit into your template and immediately work without any modification. For one thing, the comment at the end of this line was meant to tell you to do something:
Code:
    for (var k = Asc('a'); k <= Asc('d'); k++) // <- change 'd' to however many you need to iterate
Because, since I hadn't seen the template, I had no way of knowing how many repeats you had. (My ESP is not working well today.)

But it's more complicated than that: The number of repeats can be different for each page, and it also seems that, for some reason, you don't always want to start with 'a', which I don't get, but the rule can account for that:
Code:
var Name = Field("REA_FirstName");
var Headshot = Field("REA_Headshot");
var Logo = Field("REA_Logo");

for (var i = 1; i <= 12; i++)
{
    for (var k = Asc('a'); k <= Asc('d'); k++)
    {
        var suffix = "..P" + FormatNumber("00", i) + Chr(k);
        if (Name == "" || Headshot == "")
        {
            SuppressFrame("REA..TXT..Data" + suffix);
            SuppressFrame("REA..TXT..Message" + suffix);
            SuppressFrame("REA..IMG..Headshot" + suffix, true);
            SuppressFrame("REA..IMG..CompanyLogo" + suffix, true);
            SuppressFrame("REA..TXT..CompanyName" + suffix);
        }

        if (Logo != "")
        {
            SuppressFrame("REA..TXT..CompanyName" + suffix);
        }
    }
}

function SuppressFrame(name, graphic)
{
    try
    {
        var frame = graphic ? FindGraphicFrame(name) : FindTextFrame(name);
        frame.suppress = true;
    }
    catch (e)
    {
    }
}
If you name all of the frames consistently, with the "P" and the two-digit page number and another letter, I think that will work, or at least not throw any errors. But I can't really test it without the data file.

Having gone through that exercise, though, I still think it would have been easier to set this job up with repeatable components. But since you have already laid everything out this way, it might be better to stay the course now. But I can't really try another approach without the data anyway.
__________________
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; August 1st, 2017 at 06:08 PM..
Reply With Quote
  #9  
Old August 3rd, 2017, 11:26 AM
NAFPRm's Avatar
NAFPRm NAFPRm is offline
Forum n00b
 
Join Date: Dec 2015
Location: Orange County, CA
Posts: 6
Default Re: OnRecordStart - applying to multiple pages

Sorry about the wrong field names. It's not that way on my end. Maybe I uploaded the wrong file somehow.

I tried to upload the source file, but it said "invalid file".

I tried the code you provided though and it appears to have worked. Thank you!
Reply With Quote
Old August 3rd, 2017, 11:51 AM
NAFPRm
This message has been deleted by NAFPRm. Reason: made a mistake. content is invalid.
Reply

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 08:34 PM.


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