Jump to content

OnRecordStart Problem


KToomey

Recommended Posts

I have an OnRecordStart rule that is not acting the way I think it should. I have a work-around by using IF statements versus the SWITCH rule I tried to use. However, I thought I'd ask here to see why this doesn't work the way I think it should:

 

FusionPro.Composition.SetBodyPageUsage("INVY_SHOPPERS_SRP", false);
FusionPro.Composition.SetBodyPageUsage("INVENTORY SRP", false);
FusionPro.Composition.SetBodyPageUsage("INVENTORY ONLY", false);
FusionPro.Composition.SetBodyPageUsage("SHOPPERS SRP", false);
FusionPro.Composition.SetBodyPageUsage("SHOPPERS ONLY", false);
switch (Field("VERSION"))
{
   case "Invy, Shoppers, SRP": FusionPro.Composition.SetBodyPageUsage("INVY_SHOPPERS_SRP", true);
   case "Inventory, SRP": FusionPro.Composition.SetBodyPageUsage("INVENTORY SRP", true);
   case "Inventory": FusionPro.Composition.SetBodyPageUsage("INVENTORY ONLY", true);
   case "Shoppers, SRP": FusionPro.Composition.SetBodyPageUsage("SHOPPERS SRP", true);
   case "Shoppers": FusionPro.Composition.SetBodyPageUsage("SHOPPERS ONLY", true);
}

What is actually happening is that the case statement that matches is working and turning on the page that is should, but every case statement listed after that one is also turning on its respective page.

 

Anyone have any idea why?

Link to comment
Share on other sites

Why not try this simpler method of driving your versions.

 

Set all of your versions as unused body pages, but named the exact name that is in your version data field.

 

Then use this OnRecordStart Rule

 

FusionPro.Composition.SetBodyPageUsage(Field("VERSION"), true)

Link to comment
Share on other sites

I'm not sure I know what you mean by a break. I thought I just needed a semicolon after each statement (which I have in there).

The break after each case tells FP to "break" out of the switch loop. Without the break all the lines of code after the case that matches your data will execute. So your individual cases should look like:

case "option1": 
FusionPro.Composition.SetBodyPageUsage("page1", true);
break;

case "option2": 
FusionPro.Composition.SetBodyPageUsage("page2", true);

Without the break, option2 will correctly use page 2, but option1 will use page1 AND page2.

 

Alternatively, you can use the method sschardan suggests. This entails setting all your pages to be unused in the Manage Pages dialog and to name them the same name as is used in the data (i.e. if the page name is "SHOPPERS ONLY" then the value in the Field("Version") is also "SHOPPERS ONLY"). Then you can just use the single line

FusionPro.Composition.SetBodyPageUsage(Field("VERSION"), true);

which will activate the page that matches the field value for each record.

Link to comment
Share on other sites

OK, I understand the break now, but how is it that something like this would work without the break?

switch (Field("VERSION"))
{
   case "Invy, Shoppers, SRP": return "1";
   case "Inventory, SRP": return "2";
   case "Inventory": return "3";
   case "Shoppers, SRP": return "4";
   case "Shoppers": return "5";
}

Link to comment
Share on other sites

Also, I just tried this code using the "break;" syntax and got the same results as with my original code:

FusionPro.Composition.SetBodyPageUsage("INVY_SHOPPERS_SRP", false);
FusionPro.Composition.SetBodyPageUsage("INVENTORY SRP", false);
FusionPro.Composition.SetBodyPageUsage("INVENTORY ONLY", false);
FusionPro.Composition.SetBodyPageUsage("SHOPPERS SRP", false);
FusionPro.Composition.SetBodyPageUsage("SHOPPERS ONLY", false);
switch (Field("VERSION"))
{
   case "Invy, Shoppers, SRP":
      FusionPro.Composition.SetBodyPageUsage("INVY_SHOPPERS_SRP", true);
      break;
   case "Inventory, SRP": 
      FusionPro.Composition.SetBodyPageUsage("INVENTORY SRP", true);
      break;
   case "Inventory": 
      FusionPro.Composition.SetBodyPageUsage("INVENTORY ONLY", true);
      break;
   case "Shoppers, SRP": 
      FusionPro.Composition.SetBodyPageUsage("SHOPPERS SRP", true);
      break;
   case "Shoppers": 
      FusionPro.Composition.SetBodyPageUsage("SHOPPERS ONLY", true);
      break;
}

Link to comment
Share on other sites

sschardan:

 

Your solution works (for this instance), but we can't guarantee that the client won't be putting characters in that field that wouldn't be valid in a page name. Nor do we dictate how many characters long that field is.

Link to comment
Share on other sites

OK, I understand the break now, but how is it that something like this would work without the break?

switch (Field("VERSION"))
{
   case "Invy, Shoppers, SRP": return "1";
   case "Inventory, SRP": return "2";
   case "Inventory": return "3";
   case "Shoppers, SRP": return "4";
   case "Shoppers": return "5";
}

The above code works because the return functions as a break with no code being executed following the valid return. Since returns are not used in callback rules, the break is needed to avoid running the additional lines of code in the loop.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...