draco66 Posted August 4, 2015 Share Posted August 4, 2015 Is there any way to code a template so that all fields are in Upper Case rather than creating a rule for each field? And while I'm asking (because I know this will be the next request from the client) is there a way to apply Upper Case to a bunch of fields, but not all of them, with some code? I have a document with several hundred fields so creating rules for each is going to be a huge task. I know I can manipulate the case in Excel but this is ultimately going to end up as a MarcomCentral job so the template has to handle all the formatting. Thank you for any suggestions. Quote Link to comment Share on other sites More sharing options...
David Miller Posted August 4, 2015 Share Posted August 4, 2015 Is there any way to code a template so that all fields are in Upper Case rather than creating a rule for each field? OnRecordStart Callback Rule: for (var field in FusionPro.Fields) FusionPro.Composition.AddVariable(field, ToUpper(Field(field))); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 4, 2015 Share Posted August 4, 2015 You can do this in OnRecordStart: for (var fieldName in FusionPro.Fields) FusionPro.Composition.AddVariable(fieldName, ToUpper(RawTextFromTagged(TaggedDataField(fieldName)))); Two caveats with this: 1. It affects only fields called out directly in text frames. If you use a field value in a JavaScript rule, you'll need to call ToUpper on it. 2. It may not work with full tagged markup data field values, such as any data entered in MarcomCentral's Rich Text Editor. Quote Link to comment Share on other sites More sharing options...
draco66 Posted August 4, 2015 Author Share Posted August 4, 2015 Thank you for the input. I will give it a try and see if it works correctly for us. Quote Link to comment Share on other sites More sharing options...
step Posted August 4, 2015 Share Posted August 4, 2015 And while I'm asking (because I know this will be the next request from the client) is there a way to apply Upper Case to a bunch of fields, but not all of them, with some code? By altering the previous solutions, you can exempt certain fields by adding them to an "exclusions" array like this: var exclusions = [ "Field Name1", "Field Name2", // Add as many as you like ]; for (var i in FusionPro.Fields){ if (exclusions.indexOf(i)<0) FusionPro.Composition.AddVariable(i, ToUpper(RawTextFromTagged(TaggedDataField(i)))); } Here "Field Name1" and "Field Name2" will not be upper-cased but the rest of your fields will be. If the list of exclusions is longer than the list of fields that should be upper-cased, you can use this code: var upper = [ "Field Name1", "Field Name2", // Add as many as you like ]; for (var i in FusionPro.Fields){ if (upper.indexOf(i)+1) FusionPro.Composition.AddVariable(i, ToUpper(RawTextFromTagged(TaggedDataField(i)))); } Here, only fields in the "upper" array will be altered ("Field Name1" & "Field Name2"). Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 4, 2015 Share Posted August 4, 2015 If the list of exclusions is longer than the list of fields that should be upper-cased, you can use this code: var upper = [ "Field Name1", "Field Name2", // Add as many as you like ]; for (var i in FusionPro.Fields){ if (upper.indexOf(i)+1) FusionPro.Composition.AddVariable(i, ToUpper(RawTextFromTagged(TaggedDataField(i)))); } Here, only fields in the "upper" array will be altered ("Field Name1" & "Field Name2"). Or just iterate the array, like so: var upper = [ "Field Name1", "Field Name2", // Add as many as you like ]; for (var i in upper) FusionPro.Composition.AddVariable(upper[i], ToUpper(RawTextFromTagged(TaggedDataField(upper[i])))); Quote Link to comment Share on other sites More sharing options...
draco66 Posted August 6, 2015 Author Share Posted August 6, 2015 Thank you for the help with this. I ended up using the array method and it worked great. However, now the client wants to apply a FormatNumber rule to a bunch of fields just like we did for the Upper Case rule. I have tried several options trying to build off of the code provided above but I can't get it to work. How can I edit this code to apply the FormatNumber to a list of fields? The format they need is "$0.00". Thank you again. Quote Link to comment Share on other sites More sharing options...
draco66 Posted August 6, 2015 Author Share Posted August 6, 2015 Let me clarify my last post a bit. I did write code to do the format number and it works. However I simply added a copy of the code below what was provided for the upper case rule and edited it. Now when the job runs the format number works but the uppercase rule is being ignored. How can I write it to do both the upper case rule on a list of fields and the format number rule on another list of fields? Quote Link to comment Share on other sites More sharing options...
draco66 Posted August 6, 2015 Author Share Posted August 6, 2015 OK, Sorry for the bother. I kept plugging away and got it to work. The code now does both the upper case on one list of fields and the format number on another list of fields. I had one variable reference incorrect and it was throwing the whole thing off. Thanks again for your help. Quote Link to comment Share on other sites More sharing options...
step Posted August 6, 2015 Share Posted August 6, 2015 This code makes use of two arrays; one is a list of fields that should be made upper-cased and the other is a list of fields that need price formatting applied to them: var upper = [ "Field Name1", "Field Name2", // Add as many as you like ]; var prices = [ "Field3", ]; for (var i in FusionPro.Fields){ var val = (prices.indexOf(i)+1) ? FormatNumber("$0.00", RawTextFromTagged(TaggedDataField(i))) : ToUpper(RawTextFromTagged(TaggedDataField(i))) if (upper.concat(prices).indexOf(i)+1) FusionPro.Composition.AddVariable(i, val); } 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.