How to convert fields in lower case/upper case within Info path forms

Info path forms does not have any function to convert fields to lowercase or uppercase but there is an easy way to do it by using the translate function.
Basically, the translate function returns the first argument string with occurrences of characters in the second argument string replaced by the character at the corresponding in the third argument.

Using the translate function we can convert fields from upper case to lower case, first word in upper case... or even use it to remove all the dashes and colons. The Translate function is better than the Replace function as can change several words at the same time.

If we want every single character to get converted, we will have to specify every letter in the alphabet in upper case and then lower case to make sure every character will get converted.
These are some examples:
  • Converting from UPPER case to Lower case:
translate(FieldToConvert, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")
  • Converting from lower case to UPPER case:
translate(FieldToConvert, "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  • Converting first letter to UPPER case:
concat(substring(translate(FieldToConvert, "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 1, 1), substring(FieldToConvert, 2, string-length(FieldToConvert) - 1))

If you are going to use this function more than expected, you might consider to create a "Template Part" with 2 fields (uppercase and lowercase), then when you  need to use it, you will include the "Template Part" to your form and build expressions like these:

  • Translate(FiledToConvert, uppercase, lowercase)
  • Translate(FiledToConvert, lowercase, uppercase)
  • concat(substring(translate(FieldToConvert, lowercase, uppercase), 1, 1), substring(FieldToConvert, 2, string-length(FieldToConvert) - 1))
In this way you will avoid to type the full alphabet every single time that you want to use it.





Comments

Popular posts from this blog

How to auto save a browser enabled info path form every X minutes in Sharepoint 2007, 2010 and 2013

Auto-populate the person/Group picker from the current user on InfoPath 2007/2010/2013