Jump to content

Use proper template based on value in multiple fields


KDeLay

Recommended Posts

I have a business card that the client would like to have multiple locations on the backside of the card. Due to my poor ability to understand or write javascript I decided to make a template for each option. Meaning if they have a value in "Location 1" it pulls the "Location 1" backside. Now when I tried to ask it to see if there is a value in "location 2" use "location2" I'm not getting the results I was expecting.

There will be a total of 8 different locations on the back of the card. Before I write all of this, can you tell me why this code isn't working? Currently when I do the compose, all of the records generate "Location1" even though record #2 has 2 locations:

 

if (Field("Phone") == "" && Field("Location1")!= "") {
    FusionPro.Composition.SetBodyPageUsage("FrontNoOffice",true);
    FusionPro.Composition.SetBodyPageUsage("Location1",true);
} else if (Field("Cell") == "" && Field("Location1")!= "") {
    FusionPro.Composition.SetBodyPageUsage("FrontNoCell",true);
    FusionPro.Composition.SetBodyPageUsage("Location1",true);
} else if (Field("Phone")!= "" && Field("Cell")!= "" && Field("Location1")!= "") {
    FusionPro.Composition.SetBodyPageUsage("FrontAll",true);
    FusionPro.Composition.SetBodyPageUsage("Location1",true);
} else if (Field("Phone") == "" && Field("Location2")!= "") {
    FusionPro.Composition.SetBodyPageUsage("FrontNoOffice",true);
    FusionPro.Composition.SetBodyPageUsage("Location2",true);
} else if (Field("Cell") == "" && Field("Location2")!= "") {
    FusionPro.Composition.SetBodyPageUsage("FrontNoCell",true);
    FusionPro.Composition.SetBodyPageUsage("Location2",true);
} else if (Field("Phone")!= "" && Field("Cell")!= "" && Field("Location2")!= "") {
    FusionPro.Composition.SetBodyPageUsage("FrontAll",true);
    FusionPro.Composition.SetBodyPageUsage("Location2",true);
}

Link to comment
Share on other sites

Some sample data would be helpful, but without seeing anything, this should effectively replace all those if/elses:

FusionPro.Composition.SetBodyPageUsage("Location1", Field("Location1"));
FusionPro.Composition.SetBodyPageUsage("Location2", Field("Location2"));
FusionPro.Composition.SetBodyPageUsage("FrontNoOffice", !Field("Phone"));
FusionPro.Composition.SetBodyPageUsage("FrontNoCell", !Field("Cell"));
FusionPro.Composition.SetBodyPageUsage("FrontAll", Field("Phone") && Field("Cell"));

There is some obvious logic issues though, like what happens if there is no locations or no phone numbers at all? Either way, maybe this will fix it.

Link to comment
Share on other sites

If you change
FusionPro.Composition.SetBodyPageUsage("Location2", Field("Location2"));
to
FusionPro.Composition.SetBodyPageUsage("Location2", Field("Location2") && !Field("Location1"));
that should fix that issue, assuming you want to default to Location1.

I'm not sure what you want if there's no phone or cell though.

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