Jump to content

OnRecord Start rule for page selection Error


Recommended Posts

I have a multi-page PDF that will use only one of the pages based on the state the user selects. I've set all of the pages to "Unused" under manage pages, and have created a rule for OnRecordStart. This rule works fine and gives me the results I expect. However, it gives me the error "Function Does Not Return a Value" when I save the rule. It also gives me an error when I compose it, but the composed file IS correct. I'm guessing that my script is missing something. Here's what I have in OnRecordStart:

 

if (Field("State") == "Florida")

{

FusionPro.Composition.SetBodyPageUsage("MC34310_FL", true);

}

 

else if (Field("State") == "New Hampshire")

{

FusionPro.Composition.SetBodyPageUsage("MC34285_NH", true);

}

 

else if (Field("State") == "New York")

{

FusionPro.Composition.SetBodyPageUsage("MC34467_NY", true);

}

 

else if (Field("State") == "Texas")

{

FusionPro.Composition.SetBodyPageUsage("MC34700_TX_1210", true);

}

else

{

FusionPro.Composition.SetBodyPageUsage("MC34188", true);

}

Link to comment
Share on other sites

Also, set the first page to "used" and the rest of the pages in the template to "Unused".

This is the 2nd time I have seen you post this advice. Can you explain your logic?

 

It is perfectly acceptable to have all pages in your template set as Unused in the Manage Pages dialog as long as your callback rule activates at least one page for every record.

Link to comment
Share on other sites

I have a multi-page PDF that will use only one of the pages based on the state the user selects. I've set all of the pages to "Unused" under manage pages, and have created a rule for OnRecordStart. This rule works fine and gives me the results I expect. However, it gives me the error "Function Does Not Return a Value" when I save the rule. It also gives me an error when I compose it, but the composed file IS correct. I'm guessing that my script is missing something.

What do you mean you get an error when you save the rule? When you click Validate? Callback rules shouldn't require a return value. Are you sure that you created a callback rule? What is the Return Type shown in the Rules dialog?

 

Also, your logic seems fine, but I would collapse all of those "if/else if" statements into a "switch" statement, like so:

var pageName = "";
switch (Field("State"))
{
   case "Florida":
       pageName = "MC34310_FL";
       break;

   case "New Hampshire":
       pageName = "MC34285_NH";
       break;

// ...
// etc.
// ...

   default:
       pageName = "MC34188";
}

FusionPro.Composition.SetBodyPageUsage(pageName, true);

Or, even more succinctly:

var StateToPageNames =
{
   "Florida": "MC34310_FL",
   "New Hampshire": "MC34285_NH",
   // etc.
};

var pageName = StateToPageNames[Field("State")] || "MC34188";
FusionPro.Composition.SetBodyPageUsage(pageName, true);

Of course, the most succinct way to do it is to simply give the pages the same names as the states, and then the entire rule collapses down to this:

try
{
   FusionPro.Composition.SetBodyPageUsage(Field("State"), true);
}
catch (e)
{
   Print(e);
   FusionPro.Composition.SetBodyPageUsage("NoState", true);
}

Link to comment
Share on other sites

I have tried several iterations of the rule, including the simplified switch rule such as the one you suggested, but I still get the same error, "Function does not return a value."

 

I have double-checked the names of the pages and they do match what is in my rule.

 

It is a Callback rule – an OnRecord Start rule.

 

I have tried writing a rule to do the opposite, to initially have all my pages set to "Used" and then have the rule turn off all the unwanted pages. That rule does not give me an error message, but is a very long and cumbersome rule. It is almost like the program wants to have at least one page initially set to "Used" under Manage Pages. And as I said before, it WORKS, but it gives me an error message anyway. I hate to just ignore the message, but I'm not sure what is causing it.

Link to comment
Share on other sites

I've found out the error!

I was working on a file that a coworker had started, and discovered that she had named her rule OnRecordStart, but that it wasn't the callback rule. I've copied my rule over to the OnRecordStart Callback rule, and it now works without an error.

 

Thanks for the feedback!

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...