Jump to content

If the Resource doesn't exist...


geeool

Recommended Posts

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.

 

 

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

if (tagImage.exists) { 
   return tagImage;
   }
else    {
   return Resource("error.pdf");
   }

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

I see. The problem is on the first line:

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:

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:

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:

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...