Fetching multiple fields to create a neat and orderly list (formatted and not empty)
I have 3 email address fields in a form: Email_1, Email_2, and Email_3.
I'd like to:
- fetch all 3 fields based on certain criteria,
- combine them together into a single list,
- lowercase everything, then
- remove empty elements.
... all while using the least number of loops etc. (tight code).
All I've come up with thus far is:
- fet = Form[Criteria];
- emails = fet.Email_1.getall();
- emails.addAll(fet.Email_2.getall());
- emails.addAll(fet.Email_3.getall());
- info emails;
- // but if any of the Email fields are empty, I get unwanted commas.
I know at this point I could run a loop to add each email to a NEW list while simultaneously ignoring empty values (.length() = 0) and lowercasing anything else, but that seems inelegant, and my gut tells me I'll want to learn how to do this in the most elegant way.
Any thoughts from the community?