KDeLay Posted June 12 Share Posted June 12 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); } Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted June 12 Share Posted June 12 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. Quote Link to comment Share on other sites More sharing options...
KDeLay Posted June 12 Author Share Posted June 12 So in theory that worked, but it also resulted in someone who has 2 locations selected to then have 2 backs, which is why I was using the if statements. I've attached my template/resources files here Data.zip Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted June 12 Share Posted June 12 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.