Jump to content

Change Case of Multiple Fields with Single Rule


JR9

Recommended Posts

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.

Link to comment
Share on other sites

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:

 

image.png.792fce2bab74e2a0c2387444adb1f952.png

 

That previews like this:

image.png.76e663da20260aa155423671aa51abfe.png

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...

 

Link to comment
Share on other sites

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.

.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...