Insert commas and word "and" into a list from a multiple select field?

Topic Labels: Automations
587 1
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

I’m trying to set up an automated email that fills in the contents of a multiple select field. Is there a way to insert the multiple select field in something like a plain english list?

For example, I have a multiple select that has [Sam; Suzy; Pete]. I would like to insert the sentence “Sam, Suzy, and Pete” into my email.


1 Reply 1
6 - Interface Innovator
6 - Interface Innovator

Here is an implementation in the Scripting App:

// 🧲
const list = input.config().any_list

// 🧞‍♂️
function makeSentence(list) {
        case 1: 
            output.set('sentence', list[0]);
        case 2: 
            let two = list
                    .join(' and ')
            output.set('sentence', two);
    default :
            let more = list.length ? list
                    .slice(0, list.length - 1)
                    .join(', ')
                    + ', and ' + list.slice(-1)
                : console.error('The list was totally empty!')
                output.set('sentence', more)

// ▶

// someday this will be the answer:

Let me know if that works for you as it is something that I am going to need very shortly in my own base. Thanks!