#1
|
||||
|
||||
![]()
Is it possible to determine whether a text frame of a certain name exists?
I'm populating (via OnRecordStart) a series of text frames with variable information and if the text frame doesn't exist for a version, I don't want FP to attempt to assign content to it. I realize that this won't be an issue during composition but I'm mainly asking in order to not get errors at validation. Here's what I'm trying to do: Code:
(FindTextFrame("Rate1_" + Field("version")).exists) ? FindTextFrame("Rate1_" + Field("version")).content = Field("rate1") : ""; (FindTextFrame("Rate2_" + Field("version")).exists) ? FindTextFrame("Rate2_" + Field("version")).content = Field("rate2") : "";
__________________
Ste Pennell FusionPro VDP Creator 9.3.15 Adobe Acrobat X 10.1.1 Mac OS X 10.12 |
#2
|
|||
|
|||
![]()
You should be able to use...
try { whatever code } catch (e) { if whatever code errors, run this code } |
#3
|
||||
|
||||
![]()
Sorry to pull up such an old post but I was unable to find anything similar. I'm running into the same issue where I need to check if a frame exists in validation.
Using the Try/Catch method still causes the validator to return "null". Is there any way around that? |
#4
|
||||
|
||||
![]() Quote:
A try/catch statement doesn't make a rule return anything, unless there's a return statement inside the catch block. Also, you should be calling FindTextFrame inside of the OnRecordStart callback rule, which doesn't need to return anything anyway. So... I'm not sure what the problem is in some code that I can't see.
__________________
Dan Korn FusionPro Developer / JavaScript Guru / Forum Moderator PTI Marketing Technologies | Printable | MarcomCentral 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)}); ![]() |
#5
|
||||
|
||||
![]()
Maybe this will help. Here's how I would answer the original question. Again, these examples would all be in the OnRecordStart rule.
Code:
try { FindTextFrame("Rate1_" + Field("version")).content = Field("rate1"); } catch (e) { } try { FindTextFrame("Rate2_" + Field("version")).content = Field("rate2"); } catch (e) { } Code:
var myFrame; try { myFrame = FindTextFrame("your frame name"); } catch (e) { Print('Text frame not found!'); // <- or skip this if you want } if (myFrame) { myFrame.content = "Hello there!"; // <- or whatever else you need to do } Code:
function TryToFindTextFrame(name) { try { return FindTextFrame(name); } catch (e) { Print('Text frame "' + name + '" not found!'); // <- or skip this if you want return null; } } Code:
var myFrame = TryToFindTextFrame("your frame name"); if (myFrame) myFrame.content = "Hello there!"; Code:
function SetTextFrameContent(frameName, content) { try { FindTextFrame(frameName).content = content; } catch (e) { Print('Text frame "' + frameName+ '" not found!'); // <- or skip this if you want } } Code:
SetTextFrameContent("your frame name", "Hello there!"); Code:
SetTextFrameContent("Rate1_" + Field("version"), Field("rate1")); SetTextFrameContent("Rate2_" + Field("version"), Field("rate2"));
__________________
Dan Korn FusionPro Developer / JavaScript Guru / Forum Moderator PTI Marketing Technologies | Printable | MarcomCentral 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; January 16th, 2018 at 05:48 PM.. |
#6
|
||||
|
||||
![]()
Those examples were all very helpful.
I'll try to explain where the issue is. I have a series of templates that all use very similar javascript for the OnRecordStart callback but also require the operator to modify the text frames on a per job basis. Instead of maintaining all the code in each template I am using the Load function to bring in a single JS file. These templates will be used by operators that would be unable to diagnose javascript issues but can understand errors returned by validation. The thought was to have them simply open OnRecordStart and tap the validate button. If everything checks out, great. But if one of the text frames is missing, then it would return an error specified in the script. This is where my confusion came in. If you put return "test" directly into OnRecordStart, it will actually return "test" to the user. However, if you put return "test", or anything else, into an externally loaded JS file, it returns "null". I was attempting the try/catch method and instead of nothing happening, I wanted to use return to return an actual "hey, you forgot to put in the text frame", instead it returns "null". So, the examples all work fine, I guess the real issue is I am unable to return a custom message when text frame is not found. |
#7
|
||||
|
||||
![]() Quote:
Quote:
I suspect that you're putting the "return" in the wrong place. The thing about an external JS file is that it doesn't "return" anything. Your external JS file can have one or more functions in it, and your rules can call those functions, and each function can return something, but that's not the same as just putting a "return" statement in the JS file, outside of any function. Again, though, instead of having to guess at what's in your JS file, it would be easier to for me diagnose it if I could look at it. Furthermore, if there's really an error that you want the template designer to see, then instead of simply returning a message, you probably want to throw it instead, so that it'generates an exception. This has a couple of advantages over simply a return value: First, the box that pops up when you click Validate will have an error icon with it, which denotes an error condition much more explicitly than just the default message box with the title "Expressions OK". Second, the error message pops up when you try to save the rule, even if you don't click Validate. More about how to throw an exception instead of just returning a message below.... Also, putting on my moderator hat, it seems that your question is not really about determining whether a frame exists (the original question in this thread). Your question is really about how to return an error from an external JS file to the Rule Editor at validation time. So it really should be a new thread for this new question. And even if we figure it out the answer to your question here, that answer will only serve to confuse anyone who finds this thread later and just wants to know the answer to the original question, especially since it's highly unlikely that they'll be using an external JS file. Quote:
Quote:
So, let's try to answer your question about returning an error from an external JS file. First of all, what's wrong with the exception message that gets thrown by default when the a frame with the name passed to FindTextFrame isn't found? You know, "Error in FindFrame, no frame named 'Rate1_whatever'"? Anyway, since you don't like that message, you can certainly throw whatever exception message you want, like so: Code:
function TryToFindTextFrame(name) { try { return FindTextFrame(name); } catch (e) { throw 'Hey, you forgot to put in the text frame named "' + name + '"!'; } } Code:
function TryToFindTextFrame(name) { try { return FindTextFrame(name); } catch (e) { throw "Error calling external JS function: " + e; } } Code:
if (!Field("version")) throw "Invalid data!";
__________________
Dan Korn FusionPro Developer / JavaScript Guru / Forum Moderator PTI Marketing Technologies | Printable | MarcomCentral 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; January 17th, 2018 at 02:21 PM.. |
#8
|
||||
|
||||
![]()
Attached is my template with the external JS file. When you open OnRecordStart and click validate, it returns "null". If I paste the code from the JS file directly into OnRecordStart, it returns the error as you would expect.
I get where you are coming from trying to keep things organized. Hopefully this will make more sense with the attached sample. |
#9
|
||||
|
||||
![]()
Try putting your logic in a function (called "validateTextFrames" for example) and then call it from your OnRecordStart callback.
JavaScript file: Code:
function validateTextFrames() { // Your required frames. var frames = [ 'Your First Text Frame Name', 'Your Second Text Frame Name' ]; for (var i in frames) { try { var frameName = frames[i]; if (FindTextFrame(frameName)) delete frames[i]; } catch (e) {} } if ((frames = frames.filter(String)).length) ReportError('Missing required text frame(s):\n"' + frames.join('"\n"') + '"'); } Code:
Load("errortest.js"); validateTextFrames(); JS file: Code:
function testReturn() { return 'hello from your external js file!'; } Code:
Load("errortest.js"); return testReturn();
__________________
Ste Pennell FusionPro VDP Creator 9.3.15 Adobe Acrobat X 10.1.1 Mac OS X 10.12 |
#10
|
||||
|
||||
![]()
Adding that extra function call directly to OnRecordStart did the trick. It's working perfectly now. It's just a matter of updating all the templates to include that extra line. Thanks so much for all the help
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | |
|
|