PDA

View Full Version : Web-To-Print: Overwriting resource text


Fabian
December 15th, 2008, 02:46 PM
hello all, im building an online template. this template will contain 1 trigger field (drop down text) in the web form that will utilize a rule to bring in a text resource into a specified text frame in the template. the client also wants the ability to overwrite that text resource. any ideas on how to do this? this is how im invisioning the rule:

if field "MealType" eqauls "Pizza" in the web form, then return text resource "PizzaResource" into specified text frame in the template. Now there will be another field named "CustomMessage" that will be a multi-line text box in the web form, and if the user decides that they want to type in their own message then it will over write "PizzaResource".

can anyone help me write this rule?

Dan Korn
December 16th, 2008, 12:53 PM
if (Field("CustomMessage"))
return Field("CustomMessage");
//else
if (Field("MealType") == "Pizza")
return Resource("PizzaResource");
//else
return "Don't you want a pizza?"

Fabian
December 16th, 2008, 01:15 PM
thanks a bunch for the reply Dan. if i have multiple selections, would this be correct?:

if (Field("CustomMessage"))
return Field("CustomMessage");
//else
if (Field("MealType") == "Pizza")
return Resource("PizzaResource");
//else
if (Field("MealType") == "Salmon")
return Resource("SalmonResource");
//else
if (Field("MealType") == "Ravioli")
return Resource("RavioliResource");
//else
if (Field("MealType") == "Pasta")
return Resource("PastaResource");
//else
return "Don't you want a pizza?"also, what does the bottom line of the code mean. is it actually returning "Don't you want a pizza?" in the text frame? could i remove that last line of code?

Dan Korn
December 16th, 2008, 01:55 PM
Yes, but most of that logic could be accomplished more easily with a simple Switch Wizard-based rule instead of using JavaScript. Or you could generalize the logic like so:
if (Field("CustomMessage"))
return Field("CustomMessage");
//else
return Resource(Field("MealType") + "Resource");
So that you don't have to keep on adding lines to the rule every time you add a new meal type to your job.

The last line at the end of my previous post will indeed return the literal text "Don't you want a pizza?" in the text frame, but only if none of the other conditions are met. Since you didn't specify what you wanted to happen if the field "MealType" doesn't equal "Pizza" in the web form, I had to guess what to do in that case. If you remove that last line, you'll get an error about "Rule does not return a value" in your log file for any record where the field value is not among the list of meal types you're checking for, and in the output, you'd get the rule name in curly braces. In my latest example directly above, you'd get an error to the effect of "Error: In Resource(), no resource named SpaghettiResource", but you'd still get the rule name in curly braces in the output. One way to handle that would be to catch the exception, like so:
if (Field("CustomMessage"))
return Field("CustomMessage");
//else
try
{
return Resource(Field("MealType") + "Resource");
}
catch (e)
{
return "Error: No resource found for: " + Field("MealType");
}
Again, I don't know exactly what you want to do if you get some unexpected or invalid data, but generally it's good to anticipate errors and handle them in an explicit way instead of waiting for something to break.

P.S. Despite the thread title, none of this is really specific to FusionPro Web. You just happen to be generating the field data from a web form, but ultimately, the FusionPro composition engine just deals with input data, so this would all be the same in a job in FP Desktop with a flat data file and a column named "MealType."

P.P.S. Thanks a lot, now you made me hungry! ;)

Fabian
December 16th, 2008, 02:10 PM
thanks again for all your help dan, i think i have all the information i need to build upon.

P.S. you should see the images that accompany the resources...YUM!!:D