Skip to content

Instantly share code, notes, and snippets.

@aleksa-krolls
Last active December 5, 2018 13:37
Show Gist options
  • Save aleksa-krolls/d6274fbdfadf4260fb68ff1c4bd28a08 to your computer and use it in GitHub Desktop.
Save aleksa-krolls/d6274fbdfadf4260fb68ff1c4bd28a08 to your computer and use it in GitHub Desktop.
//Jobs are evaluated as Javascript...
//Here we are named functions from the OpenFn Mailgun language-pack: https://github.com/openfn/language-mailgun
send(
fields(
field('from', 'sebastian@gmail.com'),
field('to', 'recipient2@email.com'),
field('subject', 'Kobo: New Form Submitted'),
//Using Javascipt, you can write your own custom, anonymous functions to do whatever you desire - see function(state)
//Below I use the OpenFn dataValue() function to create a message & dynamically fill in the recipient name
field('text', function(state) {
const msgText = "A form was submitted by "+ dataValue("_submitted_by")(state) + ". Please login to review!"
return msgText
//dataValue("_submitted_by")(state) will dynamically fill the text with the "_submitted_by" value from my Kobo form
//I can use "state.data._submitted_by" instead of dataValue() and get the same result - dataValue() is the OpenFn function that accesses the source data value from state (the message)
//result will be an email with body text "A form was submitted by [Submitted By Name]. Please login to review!"
})
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment