Paul Cos Posted September 10 Posted September 10 I have business cards that shows up to 16 variations. I just need one to show when certain fields have information. I built a RecordOnStart to render different layouts. One o fthe field is a dropdown that will populate a phone number or if left blank a phone number will populate from a dropdown address (selection) _Telephone_Direct_Mobile_fax, when all 4 are selected it renders a 2 line layout. When 3 are selected it will render on 1 line My RecordOnStart RULE, this is just a sample of a couple of layouts. if (Field("Telephone") != "" || Rule("DropdownAddress_Telephone_RULE") == "") { FusionPro.Composition.SetBodyPageUsage("dropdown", false) FusionPro.Composition.SetBodyPageUsage("manual", true ) } else { FusionPro.Composition.SetBodyPageUsage("manual", false) FusionPro.Composition.SetBodyPageUsage("dropdown", true ) } if (Rule("Numbers_format_RULE_Drop_4") == "dropdown") { FusionPro.Composition.SetBodyPageUsage("dropdown", true); FusionPro.Composition.SetBodyPageUsage("manual", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("manual_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_M_F", false); FusionPro.Composition.SetBodyPageUsage("manual_T_M_F", false); } else if (Rule("Numbers_manual_RULE_4") == "manual") { FusionPro.Composition.SetBodyPageUsage("manual", true); FusionPro.Composition.SetBodyPageUsage("dropdown", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("manual_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_M_F", false); FusionPro.Composition.SetBodyPageUsage("manual_T_M_F", false); } else if (Rule("Numbers_format_RULE_Drop_T_D_M") == "dropdown_T_D_M") { cFusionPro.Composition.SetBodyPageUsage("dropdown_T_D_M", true); FusionPro.Composition.SetBodyPageUsage("manual", false); FusionPro.Composition.SetBodyPageUsage("dropdown", false); FusionPro.Composition.SetBodyPageUsage("manual_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_M_F", false); FusionPro.Composition.SetBodyPageUsage("manual_T_M_F", false); } else if (Rule("Numbers_manual_RULE_T_D_M") == "manual_T_D_M") { FusionPro.Composition.SetBodyPageUsage("manual_T_D_M", true); FusionPro.Composition.SetBodyPageUsage("manual", false); FusionPro.Composition.SetBodyPageUsage("dropdown", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_M_F", false); FusionPro.Composition.SetBodyPageUsage("manual_T_M_F", false); } else if (Rule("Numbers_format_RULE_Drop_T_M_F") == "dropdown_T_M_F") { FusionPro.Composition.SetBodyPageUsage("dropdown_T_M_F", true); FusionPro.Composition.SetBodyPageUsage("manual", false); FusionPro.Composition.SetBodyPageUsage("dropdown", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("manual_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("manual_T_M_F", false); } else if (Rule("Numbers_manual_RULE_T_M_F") == "manual_T_M_F") { FusionPro.Composition.SetBodyPageUsage("manual_T_M_F", true); FusionPro.Composition.SetBodyPageUsage("manual", false); FusionPro.Composition.SetBodyPageUsage("dropdown", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("manual_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_M_F", false); } Quote
Dan Korn Posted September 11 Posted September 11 What is the question? Do you want to know how to make this work for all 16 variations? If so, we need more information about what those 16 variations are, and under what circumstances certain pages are shown or not (i.e. the requirements). Even then, it's hard to write a rule like this "in the blind," without having the job to be able to see the effects on the output. I also strongly suspect that you can accomplish this without all these different pages being turned on and off. This sounds like a perfect scenario for having different frames, or different groups of frames, on a single page, and turning those on and off with FindTextFrame("name").suppress = true (or false) for each frame, or by putting frames into named groups (with the Groups tab on the Document Overview palette) and calling HideFrameGroup or ShowFrameGroup on them. That might make the job more maintainable, so that you don't have to change things in four places. Again, though, without seeing the job, it's hard to know the best approach. What I can say is that the code you have now can be reduced/simplified quite a bit. It's a bit confusing because you seem to be turning some pages on and then off again, but this should be equivalent to what you posted: var isManual = !!(Field("Telephone") || Rule("DropdownAddress_Telephone_RULE")); FusionPro.Composition.SetBodyPageUsage("dropdown", !isManual); FusionPro.Composition.SetBodyPageUsage("manual", isManual); FusionPro.Composition.SetBodyPageUsage("dropdown_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("manual_T_D_M", false); FusionPro.Composition.SetBodyPageUsage("dropdown_T_M_F", false); FusionPro.Composition.SetBodyPageUsage("manual_T_M_F", false); FusionPro.Composition.SetBodyPageUsage(Rule("Numbers_format_RULE_Drop_4"), true); FusionPro.Composition.SetBodyPageUsage(Rule("Numbers_format_RULE_Drop_T_D_M"), true); Or, even more succinctly, if you set all those pages to be Unused by default (in the Page Usage dialog), then it reduces down to just this: var isManual = !!(Field("Telephone") || Rule("DropdownAddress_Telephone_RULE")); FusionPro.Composition.SetBodyPageUsage("dropdown", !isManual); FusionPro.Composition.SetBodyPageUsage("manual", isManual); FusionPro.Composition.SetBodyPageUsage(Rule("Numbers_format_RULE_Drop_4"), true); FusionPro.Composition.SetBodyPageUsage(Rule("Numbers_format_RULE_Drop_T_D_M"), true); Just reducing the code like this to make it less repetitive should make maintaining it a lot easier. Quote
Paul Cos Posted September 12 Author Posted September 12 Hi Dan, Thanks for your reply. I went down a different rabbit hole in finding a solution on this BC. I attached my working zip file. So I have 4 fields <Telephone><Direct><Mobile><fax> The client is requesting when 4 numbers are used... <Telephone><Direct> <Mobile><fax>...this would be the format. and when theres 3 it will format like this <Telephone><Direct><Mobile> ...at any selection. We do have this function working This is our issue We also have a dropdown Address field that (if left empty it will populate with corresponding Telephone field) that matches up to the selected Address. Also the <Telephone>field can be manually enter and displayed on the BC, the manual function works, but the empty get an unwanted formatting result <Telephone><Direct><Mobile><fax> it should render <Telephone><Direct> <Mobile><fax> So the Rule is not seeing a difference between the <Telephone> and <Telephone empty> we are trying to use one field for 2 functions to display 4 scenarios. We are also using a 3rd party application so the client can enter information into the fields. This is part of the JavaScript var PhonesArray = [ Rule("HidePhone0Label"), Rule("HidePhone1Label"), Rule("HidePhone2Label"), Rule("HideFaxLabel") //Field("Back address 5"), //Field("Back phone number") ]; var PhonePosition = [], PhonesCount = 1, j = 0; for (i = 0; i < PhonesArray.length; i++) { if (PhonesArray[i] != "") { PhonePosition[j+1] = PhonesArray[i]; j++ PhonesCount++ } } if(PhonesCount <= 4) return Resource("3-5 Lines Resource"); else return Resource("6 Lines Resource"); Thanks for any assistance -Paul HDR_2_4Numbers_Global24_V10.zip Quote
Dan Korn Posted September 13 Posted September 13 Okay, thanks for attaching the job. There's a lot going on here, and I don't completely understand your explanation, but seeing the job helps. I have a lot of ideas of how to fix this up, but I'll just go into a couple. I simplified the rule "RULE_BackerLeading" in the attached job, to match what I think is the logic you want. I eliminated all the "FormatPhone" and "HidePhoneXLabel" rules, since they all do basically the same thing, and moved that into the single rule. Also, as I suspected, you're not really using layouts with such different content that you need entirely different pages to turn on and off. So I also eliminated the second page and the entire OnRecordStart rule. The rule simply puts a newline out in between the second and third phone number if all four are populated. The rule also calls the rule "DropdownAddress_Telephone_RULE" as needed, if the Telephone field is empty, which eliminates the need for the rule "Manual_Drop_RULE". However, I wasn't able to test this, as none of the records in the data file that you uploaded with the job had a value in the "Address1" field. But I'm pretty sure it will work. These changes keep all the logic more centralized, and, I think, easier to follow what's going on without having to look at all those other rules, and easier to maintain. Another thing I would strongly suggest is NOT hard-coding all those if statements into the rules "Manual_Drop_RULE" and "Address_RULE". What I would do instead is put all that data into a secondary data file (an XDF), called something like "Addresses Map.txt", with four columns: one for the address key (to match the "Address1" field in the main data), two more for the secondary addresses mapped in "Address_RULE", and a fourth for the phone numbers mapped in "Manual_Drop_RULE". It would look something like this: Address Key Address 1 Address 2 Phone Albany - NY - 16 Corporate Woods Blvd 16 Corporate Woods Blvd, First Floor Albany, NY 12211-2527 518.937.9500 Arlington - VA - 3001 Washington Boulevard 3001 Washington Boulevard, Suite 200 Arlington, VA 22201-2117 703.518.8500 etc. Then the "Address_RULE" would be this: var Address1 = Field("Address1"); if (!Address1) return ""; var AddressXDFFile = "Addresses Map.txt"; var AddressXDF = new ExternalDataFileEx(AddressXDFFile); if (!AddressXDF.valid) ReportError("Failed to open address file: " + AddressXDFFile); var found = AddressXDF.FindRecord("Address Key", Field("Address1")); if (found < 1) ReportError("Failed to find address: " + Field("Address1"); return AddressXDF.GetFieldValue(found, "Address 1") + '<br>' + AddressXDF.GetFieldValue(found, "Address 2"); And the "Manual_Drop_RULE" would be the same, except the last line would be: return AddressXDF.GetFieldValue(found, "Phone"); This will also make the job much more maintainable, since, if a new location is added, all you have to do is add a line to that XDF, instead of going into the job and modifying multiple rules. Also, with the XDF, you could accomplish that whole mapping without any rules at all; you could just add the XDF as a Secondary Data Source and map the fields there, and check the "Add to field list with prefix" button, with a prefix such as "ADDRESSMAP:", then you can access fields such as "ADDRESSMAP:Address 1" and "ADDRESSMAP:Phone" directly in your other rules that use them. HDR_2_4Numbers_Global24_V10-Dan-1.pdf Quote
Paul Cos Posted September 20 Author Posted September 20 Thanks Dan, I will have time next week to test this out, the client is constantly requesting more function to this project, after each time we answer them. Quote
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.