How to specify a "List" as a field in a script?

I want to be able to pass a “list” to a script. For example, I want to pass a list of recipients to an e-mail notification.

sequence:
  - service: notify.email
    data:
      message: Test Script
      target:
        - [email protected]
        - [email protected]

How would I specify a field which takes a list? The text selector would result in a string.

fields:
  email_target:
    name: Email address
    description: E-mail address of the recipient of the snapshot
    selector:
      text: null
sequence:
  - service: notify.email
    data:
      message: Test Script
      target: '{{ email_target }}'

To answer my own question. I tried three different methods:

(1) a multiline text selector. I put each e-mail address on their own line with a dash in front of them. This did not work, because the field was still treated as a string.

fields:
  email_target:
     name: Email address
     selector:
       text:
         multiline: true
sequence:
  - service: notify.email
    data:
      message: Test Script
      target: '{{ email_target }}'

(2) Use a single line text selector and input the e-mail addresses separated by a comma. When calling the smtp integration, I use split(",") to create the list of e-mail addresses. This work very well.

fields:
  email_target:
    name: Email address
    selector:
      text: null
sequence:
  - service: notify.email
    data:
      message: Test Script
      target: '{{ email_target.split(",") }}'

(3) The third solution is to use the object selector. Enter each e-mail on their own line preceded with a dash. This works as well and I do like this option the best, because the behavior is the notify service.

fields:
  email_target:
    name: Email address
    selector:
      object: null
sequence:
  - service: notify.email
    data:
      message: Test Script
      target: '{{ email_target }}'
4 Likes