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

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old March 15th, 2019, 11:51 AM
geeool geeool is offline
Junior Community Member
 
Join Date: Jun 2012
Posts: 13
Default If the Resource doesn't exist...

Hi,

This is for an online product. I'm using FusionPro Creator 10.0.6 on Windows.


I am programming tags for people to customize and order online through a MarcomCentral site. There are 100 or so different tag backgrounds that are being called in based on the SKU number the buyer enters. I have these backgrounds setup as resources and they are named with the SKU number (for example: 356304.pdf).

If the SKU number entered doesn't match one of the resources, then I want it to return error.pdf instead. My rule works fine if the resource is present, but it doesn't return the error.pdf if the resource is missing. Below is the code. Any suggestions would be appreciated.


Code:
var tagImage = Resource(Field("SKU") + ".pdf", "graphic", true);

if (tagImage.exists) { 
    return tagImage;
    }
else    {
    return Resource("error.pdf");
    }
Reply With Quote
  #2  
Old March 15th, 2019, 01:17 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,322
Default Re: If the Resource doesn't exist...

Do you actually have a NAMED resource with the RESOURCE name (not just the file name) error.pdf in your FusionPro job, in the Resources dialog? If not, then you need to change Resource on the next-to-last line of the rule to CreateResource. Either way, you also need to make sure that you have a file with the file name error.pdf in a MarcomCentral image library that's used by the job for the MarcomCentral composition.

Also, questions like this which are specific to the MarcomCentral application should really be asked in the MarcomCentral sub-forum.
__________________
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 March 18th, 2019, 12:37 PM
geeool geeool is offline
Junior Community Member
 
Join Date: Jun 2012
Posts: 13
Default Re: If the Resource doesn't exist...

Hi Dan,

I've stripped everything but the essentials out of my FusionPro file and I'm running it from my desktop, but I'm still having the problem. I do have a resource called error.pdf (see my collected files). Any insight you can give me is appreciated.


Thanks,
Attached Files
File Type: zip Barcode Test6.zip (717.7 KB, 1 views)
Reply With Quote
  #4  
Old March 18th, 2019, 01:47 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,322
Default Re: If the Resource doesn't exist...

I see. The problem is on the first line:
Code:
var tagImage = Resource(Field("SKU") + ".pdf", "graphic", true);
You're mixing up the usages of two different functions: Resource and CreateResource.

The Resource function takes only a single parameter: the name of a resource.

The CreateResource function (or new FusionProResource constructor function) requires one parameter (a file name), but can also take up to three other optional parameters: (2) the resource type, (3) a boolean "nonExistOK" value which denotes whether to set the .exists property instead of throwing an exception if the file is not found, and (4) the encoding (for text resources).*

Since you're calling the Resource function, that last parameter that you're setting to true has no effect, and if a named resource with the specified name has not been added to your FusionPro template, an exception is thrown, and the rules doesn't set any value in the InsertTag_RULE variable, as you can see if you do a full composition (not a Preview) and view the log file:
Quote:
uncaught exception: Error: In Resource(), no resource named 35630A.pdf
So my first bit of advice if you have a problem like this in the future is:
ALWAYS look in the log file.

There are two ways to fix this:

1. Put the Resource function call into a try block, so that when it fails to find the specified resource (by resource name), you can catch the exception, like so:
Code:
try
{
    return Resource(Field("SKU") + ".pdf");
}
catch (e)
{
    return Resource("error.pdf");
}
2. Change that first call to CreateResource, so that if the file name specified is not found, the .exists property is set instead of an exception being thrown:
Code:
var tagImage = CreateResource(Field("SKU") + ".pdf", "graphic", true);
if (tagImage.exists)
    return tagImage;
//else
return Resource("error.pdf");
I recommend solution number 2, because then you don't have to keep adding resources to the job in FusionPro. You can just add graphics to the image library in MarcomCentral, and they will be found by their file names.

* Note that the Resource function doesn't have the extra parameters that CreateResource does, because Resource deals with named resources in the template, and you specify the types and encodings of named resources in the Resource Editor dialog. Note that the .exists property of a resource can be set to true for a resource returned from either function (Resource or CreateResource), but the Resource function throws an exception only if there's no resource with the specified resource name. If there is a resource with the specified resource name defined in your template, then the Resource function won't throw an exception, but it may set the .exists property to false if the file for that named resource is not found. The CreateResource function, on the other hand, throws an exception right away if the file name specified is not found, unless a value of true is passed in the third parameter.
__________________
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 March 19th, 2019, 08:33 AM
geeool geeool is offline
Junior Community Member
 
Join Date: Jun 2012
Posts: 13
Default Re: If the Resource doesn't exist...

#2 worked. Also, thanks for explaining everything. It's always helpful to have a detailed response to better understand what is happening.
Reply With Quote
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 09:24 PM.


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