Skip to content
Groovy 20 – Using FOR Loop to Generate Even Numbers Series

API Name of the Text field is Text1_c.

The series will be generated in a Multi-Line Text Formula Field.

        String myString = nvl(getAttribute('Text1_c'), "0")
        String myLimit = myString.replaceAll("[^0-9]", "")
        String series = ""
        for (def i = 0; i <= Integer.parseInt(myLimit); i++) {
            def element1 = i
            def element2 = i
            element2 = element1 + element2
            element1 = element2 - element1
            series += element2 + ","
        }
        return series
        

The result of this code will generate a series of numbers based on the value of Text1_c field and display it in a formula field, as shown below:

Series Example