JR9 Posted June 5, 2024 Posted June 5, 2024 I am trying to import data from a csv file containing multiple fields of all-caps data. The fields are First Name, Last Name, Address, City, etc. I would like to know if there is a way to convert every field of the data from all-caps to proper case using just one rule, or if I have to manually create multiple rules and apply them individually to each field. I am having trouble, because, as far as I can tell, rules have a single return value, and I do not know if there is a way to modify multiple fields using just one rule. Quote
Douglas Cogan Posted June 5, 2024 Posted June 5, 2024 Hi JR9, We are working on a way in a future version that changes like this can be done without rules. We're trying to figure out a way that you can click on the variable in the text editor and mark that you want it caps, or formatted as dollars, etc. We certainly recognize it's not ideal to have so many rules just to capitalize things. One thing you can do is in OnRecordStart you can create new "variables" that are the upper case versions. Then use them in the text editor. For example, create a new OnRecordStart rule and add these lines: FusionPro.Composition.AddVariable("CapFirstName", ToUpper(Field("First Name"))); FusionPro.Composition.AddVariable("CapLastName", ToUpper(Field("Last Name"))); Then in the text editor, type in the variable CapFirstName in the variable list box. Then you can insert it: That previews like this: That way you don't have to make a rule for everything you want to capitalize. Like I said, though, we are looking into ways to do this without having to write any rules. Hopefully for version 14... Quote
DSweet Posted June 6, 2024 Posted June 6, 2024 I know about the ToUpper() function, and I use it quite a bit. However, in regard to the name field(s) in proper case that JR9 wants to use, he could do the same thing with ToTitleCase() function ... but that would not be quite proper for names. "McDonalds" would come over as "Mcdonalds" and "JoAnn" would come over like "Joann". Somehow a repository of such names would have to be kept maintaining the proper casing of such items. . Quote
Dan Korn Posted June 12, 2024 Posted June 12, 2024 You could generalize Doug's solution to make an upper-case version of every data field, like so in OnRecordStart: for (var fieldName in FusionPro.Fields) FusionPro.Composition.AddVariable("Cap" + fieldName, ToUpper(Field(fieldName))); And you could do something similar with the ToTitleCase() function. However, I have to echo DSweet's warning about ToTitleCase. As I have also noted many times here on this forum, it's not possible to write a computer algorithm that can correctly "unmake the soup" of proper names which have been capitalized to go back to their original "proper" casing, as there are no strict rules about how names are capitalized, and the capitalization can be arbitrary. It's more art than science, and even with a database of common exceptions, a computer does not get to dictate to anyone how their name should be capitalized. It's not just names like "McDonalds" that you have to worry about, it's also names like "Mies van der Rohe", "O'Neil", "Leonardo di Caprio", and uncountable other possibilities, which are impossible to fully account for. Quote
sschardan Posted October 24, 2024 Posted October 24, 2024 I successfully modified this for a particular job by using the following, where VarFix is a global function evaluating and formatting the fields: for (var fieldName in FusionPro.Fields) FusionPro.Composition.AddVariable(fieldName + "fix", VarFix(Field(fieldName))); However, I wanted to see if it was possible to limit the scope to an array of fields by doing something like this: var ChosenFields = ["Field(a)", "Field(b)", "Field(c)", "Field(d)", "Field(e)", "Field(f)", "Field(g)", "Field(h)", "Field(i)", "Field(j)", "Field(k)", "Field(l)", "Field(m)", "Field(n)", "Field(o)", "Field(p)"]; for (var fieldName in ChosenFields); FusionPro.Composition.AddVariable(fieldName + "fix", VarFix(Field(fieldName))); But it is erroring out because it is returning the index positions instead of the field names and their values. I tried adjusting by inserting an indexOf, but then it keeps giving me formatting errors. I'm sure there's a way to accomplish this, but it is evading my understanding, and any help would be greatly appreciated. Thank you 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.