Marcus Posted February 25, 2016 Share Posted February 25, 2016 I am trying to only have one coupon (resource), which can be used in 4 different positions, that uses a var1 that has different values depending on which text box is to be used. I am a not very experienced with Java, but here is what I have so far. I feel like I need some sort of way to determine which text box is to be used. if (Field("COUPON_COD") == "C1") { return("MyVar1", Field("N_VAR_1")); } if (Field("COUPON_CO2") == "C1") { return("MyVar1", Field("N_VAR_1__2")); } if (Field("COUPON_CO3") == "C1") { return("MyVar1", Field("N_VAR_1__3")); } if (Field("COUPON_CO4") == "C1") { return("MyVar1", Field("N_VAR_1__4")); } Thanks, Marcus Quote Link to comment Share on other sites More sharing options...
Marcus Posted February 29, 2016 Author Share Posted February 29, 2016 Help! I have a coupon resource that I need to change values depending on which text box is active. I wanted to have all text boxes using the same resource but changing the value of <<MyVar1>> with a rule that works by the flow of the text boxes, which I can seem to figure out. Any suggestions? Quote Link to comment Share on other sites More sharing options...
step Posted February 29, 2016 Share Posted February 29, 2016 I don't understand what you're trying to do. Can you post an example? Are you trying to a return a specific value for a variable, "MyVar1", depending on which coupon field's value is "C1"? If so, your current code could just be modified to look like this: if (Field("COUPON_COD") == "C1") { return Field("N_VAR_1"); } if (Field("COUPON_CO2") == "C1") { return Field("N_VAR_1__2"); } if (Field("COUPON_CO3") == "C1") { return Field("N_VAR_1__3"); } if (Field("COUPON_CO4") == "C1") { return Field("N_VAR_1__4"); } Or: var i = 5; while (--i > 2) if (Field("COUPON_CO" + i) == 'C1') return Field("N_VAR_1__" + i); return (Field("COUPON_COD") == "C1") ? Field("N_VAR_1") : ''; Assuming you've named your text frames, you can see a text frame's name by checking the "Re-evaluate this rule for every text flow" and entering this rule: return FusionPro.Composition.CurrentFlow.name; Quote Link to comment Share on other sites More sharing options...
Marcus Posted February 29, 2016 Author Share Posted February 29, 2016 Thanks very much for your help. I went about it a different way, but without your code I wouldn't have gotten it so soon if every. Thanks, again. Marcus Quote Link to comment Share on other sites More sharing options...
Marcus Posted February 29, 2016 Author Share Posted February 29, 2016 This was the code that I ended up with. var r = [ [Field("N_VAR_1")],[Field("N_VAR_1__2")],[Field("N_VAR_1__3")],[Field("N_VAR_1__4")] ]; var x = FusionPro.Composition.CurrentFlow.name return r[x]; Quote Link to comment Share on other sites More sharing options...
step Posted February 29, 2016 Share Posted February 29, 2016 This was the code that I ended up with. var r = [ [Field("N_VAR_1")],[Field("N_VAR_1__2")],[Field("N_VAR_1__3")],[Field("N_VAR_1__4")] ]; var x = FusionPro.Composition.CurrentFlow.name return r[x]; That works for you? As I said before, I (still) don't really understand what you're trying to do and while I'm happy if that code does what you're trying to do, I just don't understand it. You've made an array named 'r'. Within 'r' you've put 4 fields, each within their own array. So assuming you've named your frames 0,1,2, and 3, I still don't understand how that could return a unique value for each frame. If your ultimate goal is to return Field("N_VAR_1") in frame "0", Field("N_VAR_1__2") in frame "1" and so forth, you'd need to modify your code to be: var r = [ [Field("N_VAR_1")],[Field("N_VAR_1__2")],[Field("N_VAR_1__3")],[Field("N_VAR_1__4")] ]; var x = FusionPro.Composition.CurrentFlow.name return r[color="Red"][0][/color][x]; Or just get rid of the 2D array: return [ Field("N_VAR_1"), Field("N_VAR_1__2"), Field("N_VAR_1__3"), Field("N_VAR_1__4") ][FusionPro.Composition.CurrentFlow.name]; Quote Link to comment Share on other sites More sharing options...
Marcus Posted February 29, 2016 Author Share Posted February 29, 2016 I am using a flat data file that has four coupons in it. Each coupon has different value(s) for their start dates... and other jobs could have different coupons in each position. I just thought it would be easier to try and figure this out with just the values and then use it with everything else. I wanted code that would allow me to use only one resource which could be used in any position and pull the corresponding values from the file depending upon that position. I like the later code you posted, it works for me. Excuse my code, I am very unfamiliar with JavaScript, but trying to learn it. Any suggestions for rapid learning JavaScrpit code for FusionPro? Thank you for your help! Quote Link to comment Share on other sites More sharing options...
step Posted March 1, 2016 Share Posted March 1, 2016 Excuse my code, I am very unfamiliar with JavaScript, but trying to learn it. Any suggestions for rapid learning JavaScrpit code for FusionPro? No worries! I just wanted to make sure you were able to accomplish what you were trying to do. If you discover a way to rapidly learn JavaScript, please share haha. My recommendation is simply to participate in this forum. Ask questions and ask for clarification if you don't understand a solution. Of course there are video tutorials as well. 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.