Brian F. Posted January 21, 2011 Share Posted January 21, 2011 Is there a way to apply an all caps rule to all the variable fields within a text frame or do I need to make a rule for each variable? I have a customizable list of services the user can choose from. Service 1, Service 2, Service 3, etc. They are all in 1 text field. I'd really rather not make a rule for all 12 service options. Link to comment Share on other sites More sharing options...
Dan Korn Posted January 24, 2011 Share Posted January 24, 2011 You can turn all the fields in the job to uppercase by doing this in OnRecordStart: for (var field in FusionPro.Fields) FusionPro.Composition.AddVariable(field, ToUpper(Field(field)));Or, more specifically to your case: for (var i = 1; i <= 12; i++) FusionPro.Composition.AddVariable("Service " + i, ToUpper(Field("Service " + i))); Link to comment Share on other sites More sharing options...
Brian F. Posted January 24, 2011 Author Share Posted January 24, 2011 Thanks for your help! Link to comment Share on other sites More sharing options...
scubajbc Posted February 18, 2011 Share Posted February 18, 2011 Just so I make sure I know how this works... If you have a field in your data called CODE and you add a variable called CODE, then you insert CODE into a text box, FusionPro will look for a variable named CODE before it would look for a field named CODE? What if you also had a rule named CODE? Link to comment Share on other sites More sharing options...
esmith Posted February 21, 2011 Share Posted February 21, 2011 For that very reason, I have always named my rules "RULE_rule name". I suppose if I needed to add a custom variable, I would probably name it "VAR_variable name" to keep the CODEs separate. Link to comment Share on other sites More sharing options...
scubajbc Posted February 22, 2011 Share Posted February 22, 2011 For what it's worth, I made a test file and here is what I found... DataFile.csv = CODE Abcd-1234 1. Result of CODE in text box: Abcd-1234 2. Add an OnRecordStart Rule... FusionPro.Composition.AddVariable("CODE", Field("CODE").toUpperCase());Result of CODE in text box: ABCD-1234 3. Add a Rule named CODE... return Field("CODE").replace("-","#");Result of CODE in text box: Abcd#1234 Notice the Rule did not use the Variable CODE (Upper Case) it used the Field CODE (Mixed Case) Link to comment Share on other sites More sharing options...
Dan Korn Posted February 22, 2011 Share Posted February 22, 2011 If you have a field in your data called CODE and you add a variable called CODE, then you insert CODE into a text box, FusionPro will look for a variable named CODE before it would look for a field named CODE? Well, they're all variables, it's just that some variables' values come from the data file directly, some come from the return value of standard rules, and some come from "variable injection" via FusionPro.Composition.AddVariable. What if you also had a rule named CODE? That would win out in all cases, as you confirm below: For what it's worth, I made a test file and here is what I found... DataFile.csv = CODE Abcd-1234 1. Result of CODE in text box: Abcd-1234 2. Add an OnRecordStart Rule... FusionPro.Composition.AddVariable("CODE", Field("CODE").toUpperCase());Result of CODE in text box: ABCD-1234 3. Add a Rule named CODE... return Field("CODE").replace("-","#");Result of CODE in text box: Abcd#1234 Notice the Rule did not use the Variable CODE (Upper Case) it used the Field CODE (Mixed Case) Yes, this is what I would expect. The last value to be set "wins." Remember the order that things are happening here. When a record is composed, the first thing that happens is the data field is read, and all the values are assigned to variables. Then the "OnRecordStart" Callback rule gets processed; as its default comment says, it's "Called at the beginning of each record in a composition, before other rules." So any variables that you inject via the FusionPro.Composition.AddVariable function will overwrite a field value with the same name. Then, the other (non-Callback) rules get run for that record, so if you have a rule named "CODE", its return value gets set as the value of the "CODE" variable, overwriting any previous value for that record. Again, though, they're all variables. That's why the drop-down list in the Variable Text Editor has the somewhat generic caption "Variable." Whether the value comes from a data field, or a rule, or a call to FusionPro.Composition.AddVariable, or somewhere else, is transparent by the time the variable's value is merged into the text. This is by design. Link to comment Share on other sites More sharing options...
Dan Korn Posted February 22, 2011 Share Posted February 22, 2011 For that very reason, I have always named my rules "RULE_rule name". I suppose if I needed to add a custom variable, I would probably name it "VAR_variable name" to keep the CODEs separate. This is fine, but sometimes you really do want to override a variable's value from the data in a rule without having to change the design (i.e. the name of the variable called out in the text). This is one of the really neat capabilities of FusionPro, in my opinion. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.