Skip to content
Groovy 19 – Revers Strings

Here's a quick script to reverse a String value from a Text field called Text1_c and display it in a formula field.

        def myString = Text1_c
        if (myString != null) {
            def reverse = ''
            for (def i = (myString.length() - 1); i >= 0; i--) {
                reverse += myString.charAt(i)
            }
            return reverse
        } else {
            return "No Value To Reverse"
        }
        

If the text field has no value, the code will return No Value To Reverse. Otherwise, it will reverse the value in the text field, as shown below:

Example 1 Example 2