Jump to content

with Onrecordstart rule


dleahy

Recommended Posts

Have three pages in my PDF (Body 1, Body 2, Body 3)

 

Trying to get them to displayed based on values entered in a field called "SelectStyle"

 

Basically what I want to accomplish is this:

IF Field SelectStyle = "FJ Icon (M)" then display Body 2

IF Field SelectStyle = "DryJoys Tour (M)" then display Body 3

ELSE display Body 1

 

Here is what I got that's not working:

if (GetFileName(Field("SelectStyle")) == "FJ Icon (M)")
{
FusionPro.Composition.SetBodyPageUsage("Body2", true);
FusionPro.Composition.SetBodyPageUsage("Body1", false);
FusionPro.Composition.SetBodyPageUsage("Body3", false)
{
if (GetFileName(Field("SelectStyle")) == "DryJoys Tour (M)") 
{
FusionPro.Composition.SetBodyPageUsage("Body3", true);
FusionPro.Composition.SetBodyPageUsage("Body2", false);
FusionPro.Composition.SetBodyPageUsage("Body1", false)
}
else 
FusionPro.Composition.SetBodyPageUsage("Body1", true);
FusionPro.Composition.SetBodyPageUsage("Body2",false);
FusionPro.Composition.SetBodyPageUsage("Body3",false)
}}

 

Can anyone see what I'm doing wrong?!?

 

Thanks ahead of time! :)

Link to comment
Share on other sites

anyone see what I'm doing wrong?!?

 

I edited your code with a few minor adjustments. My changes are in red:

if (Field("SelectStyle") == "FJ Icon (M)")
{
FusionPro.Composition.SetBodyPageUsage("Body2", true);
FusionPro.Composition.SetBodyPageUsage("Body1", false);
FusionPro.Composition.SetBodyPageUsage("Body3", false)
[color=red]}
else[/color] if (Field("SelectStyle") == "DryJoys Tour (M)") 
{
FusionPro.Composition.SetBodyPageUsage("Body3", true);
FusionPro.Composition.SetBodyPageUsage("Body2", false);
FusionPro.Composition.SetBodyPageUsage("Body1", false)
}
else
[color=red]{[/color]
FusionPro.Composition.SetBodyPageUsage("Body1", true);
FusionPro.Composition.SetBodyPageUsage("Body2",false);
FusionPro.Composition.SetBodyPageUsage("Body3",false)
}

I also removed the GetFileName() code and some unnecessary brackets. There are other ways to set this logic up that simplify the rule, but your logic is not incorrect. ;)

Link to comment
Share on other sites

Set all three body pages to Unused in the Page Usage dialog, then the rule can simply do this:

switch (Field("SelectStyle"))
{
 case "FJ Icon (M)":
   FusionPro.Composition.SetBodyPageUsage("Body2", true);
   break;
 case "DryJoys Tour (M)":
   FusionPro.Composition.SetBodyPageUsage("Body3", true);
   break;
 default:
   FusionPro.Composition.SetBodyPageUsage("Body1", true);
}

Link to comment
Share on other sites

All,

 

I'm using the switch rule, like Dan mentioned above, on a new template I'm constructing. I need to be able to nest a else if statement in the switch rule yet I don't know quite how to do it. I have to take the code above:

 

switch (Field("SelectStyle"))
{
 case "FJ Icon (M)":
   FusionPro.Composition.SetBodyPageUsage("Body2", true);
   break;
 case "DryJoys Tour (M)":
   FusionPro.Composition.SetBodyPageUsage("Body3", true);
   break;
 default:
   FusionPro.Composition.SetBodyPageUsage("Body1", true);
}

and be able to say something like this logic:

switch (Field("SelectStyle"))
{
 case "FJ Icon (M)":
   FusionPro.Composition.SetBodyPageUsage("Body2", true);
else if Field("MemberGuestNameofEvent") == "" return
FusionPro.Composition.SetBodyPageUsage("Body4", true);
   break;
 case "DryJoys Tour (M)":
   FusionPro.Composition.SetBodyPageUsage("Body3", true);
   break;
 default:
   FusionPro.Composition.SetBodyPageUsage("Body1", true);
}

So basically I need to be able to say if SelectStyle = "FJ Icon (M)" then return "Body2" unless MemberGuestNameofEvent = "" then return "Body4"

 

Any help with that would be most appreciated!

 

-Dan

Edited by dleahy
Link to comment
Share on other sites

So basically I need to be able to say if SelectStyle = "FJ Icon (M)" then return "Body2" unless MemberGuestNameofEvent = "" then return "Body4"

It's just a matter of getting the nesting right. This should work:

switch (Field("SelectStyle"))
{
 case "FJ Icon (M)":
   if (Field("MemberGuestNameofEvent") == "")
     FusionPro.Composition.SetBodyPageUsage("Body4", true);
   else
     FusionPro.Composition.SetBodyPageUsage("Body2", true);
   break;
 case "DryJoys Tour (M)":
   FusionPro.Composition.SetBodyPageUsage("Body3", true);
   break;
 default:
   FusionPro.Composition.SetBodyPageUsage("Body1", true);
}

This is equivalent, but a bit more succinct:

switch (Field("SelectStyle"))
{
 case "FJ Icon (M)":
   FusionPro.Composition.SetBodyPageUsage(Field("MemberGuestNameofEvent") ? "Body2" : "Body4", true);
   break;
 case "DryJoys Tour (M)":
   FusionPro.Composition.SetBodyPageUsage("Body3", true);
   break;
 default:
   FusionPro.Composition.SetBodyPageUsage("Body1", true);
}

And this would be pretty much the ultimate reduction of the logic:

function PageToActivate()
{
 switch (Field("SelectStyle"))
 {
   case "FJ Icon (M)":
     return Field("MemberGuestNameofEvent") ? "Body2" : "Body4";
   case "DryJoys Tour (M)":
     return "Body3";
   default:
     return "Body1";
 }
}

FusionPro.Composition.SetBodyPageUsage(PageToActivate(), true);

I like to abstract things out as much as possible and avoid repeating similar bits of code, but that's my geeky perfectionist programmer coming out. :)

Link to comment
Share on other sites

  • 1 month later...

Dan,

 

What if you have multiple fields to verify. This logic doesn't seem to work:

 

if (Field("SelectTopicCATone") != "")
{
FusionPro.Composition.SetBodyPageUsage("Body1", true);
}
else if (Field("SelectTopicCATtwo") != "")
{
FusionPro.Composition.SetBodyPageUsage("Body2", true) && FusionPro.Composition.SetBodyPageUsage("Body1", false);
}
else if (Field("SelectTopicCATthree") != "")
{
FusionPro.Composition.SetBodyPageUsage("Body3", true) && FusionPro.Composition.SetBodyPageUsage("Body2", false) && FusionPro.Composition.SetBodyPageUsage("Body1", false);
}

Link to comment
Share on other sites

What if you have multiple fields to verify. This logic doesn't seem to work:

if (Field("SelectTopicCATone") != "")
{
FusionPro.Composition.SetBodyPageUsage("Body1", true);
}
else if (Field("SelectTopicCATtwo") != "")
{
FusionPro.Composition.SetBodyPageUsage("Body2", true) && FusionPro.Composition.SetBodyPageUsage("Body1", false);
}
else if (Field("SelectTopicCATthree") != "")
{
FusionPro.Composition.SetBodyPageUsage("Body3", true) && FusionPro.Composition.SetBodyPageUsage("Body2", false) && FusionPro.Composition.SetBodyPageUsage("Body1", false);
}

Don't use a logical AND operator (&&) in between two statements. This should work:

if (Field("SelectTopicCATone") != "")
{
 FusionPro.Composition.SetBodyPageUsage("Body1", true);
}
else if (Field("SelectTopicCATtwo") != "")
{
 FusionPro.Composition.SetBodyPageUsage("Body2", true);
 FusionPro.Composition.SetBodyPageUsage("Body1", false);
}
else if (Field("SelectTopicCATthree") != "")
{
 FusionPro.Composition.SetBodyPageUsage("Body3", true);
 FusionPro.Composition.SetBodyPageUsage("Body2", false);
 FusionPro.Composition.SetBodyPageUsage("Body1", false);
}

Again, though, if you set all three pages to be Unused initially, the rule becomes much simpler:

if (Field("SelectTopicCATone") != "")
 FusionPro.Composition.SetBodyPageUsage("Body1", true);
else if (Field("SelectTopicCATtwo") != "")
 FusionPro.Composition.SetBodyPageUsage("Body2", true);
else if (Field("SelectTopicCATthree") != "")
 FusionPro.Composition.SetBodyPageUsage("Body3", true);

Or, even better:

FusionPro.Composition.SetBodyPageUsage("Body1", Field("SelectTopicCATone") != "");
FusionPro.Composition.SetBodyPageUsage("Body2", Field("SelectTopicCATtwo") != "");
FusionPro.Composition.SetBodyPageUsage("Body3", Field("SelectTopicCATthree") != "");

Link to comment
Share on other sites

This isn't working. Keeps giving me only the first page. I wonder if it is the "else ifs"...

Ah, my last example might not work. The others should be equivalent, though.

 

At any rate, you didn't specify what the right logic should be. It seemed from your original code example that you want to activate just one page in each case. Is that not true? What exactly do you want to happen?

Link to comment
Share on other sites

Yes. In Marcom Central a user has the ability to select a bunch of different values in 3 unique dropdowns.

 

If they select a value in just the first dropdown and leave the next two blank then it should use the page "Body1" as the template.

 

If they select a value in the first and second dropdowns but not the third, then it should use the page "Body2" as the template.

 

If they select a value in all three dropdowns then it should use the page "Body3" as the template.

 

Make sense? Logically it seems my code should work but it isn't. :(

Link to comment
Share on other sites

Yes. In Marcom Central a user has the ability to select a bunch of different values in 3 unique dropdowns.

 

If they select a value in just the first dropdown and leave the next two blank then it should use the page "Body1" as the template.

 

If they select a value in the first and second dropdowns but not the third, then it should use the page "Body2" as the template.

 

If they select a value in all three dropdowns then it should use the page "Body3" as the template.

 

Make sense? Logically it seems my code should work but it isn't. :(

I see. So what happens if they select just the third but not the first two? Or does the MarcomCentral UI not allow that? In any case, I think what you want is this:

if (Field("SelectTopicCATthree"))
 FusionPro.Composition.SetBodyPageUsage("Body3", true);
else if (Field("SelectTopicCATtwo"))
 FusionPro.Composition.SetBodyPageUsage("Body2", true);
else
 FusionPro.Composition.SetBodyPageUsage("Body1", true);

Make sure you set all pages to Unused initially in the Page Usage dialog.

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