My latest try at Workflows. I have multistep, but fairly straightforward JS query that I transitioned to a workflow. It get all records that have not had notification emails sent out, send them and then updates the records saying they have been sent.
var url, rv, el; let ids = []; let fails = []
let data = await qryJobSolitsToSendCount.trigger()
if (data.length === 0) return
data = await qryJobSolitsToSend.trigger()
for (let i = 0; i < data.length; i++) {
if (data[i].tasks) {
el = data[i]
data[i].tasks.forEach(task => {
url = {
"action": "accept",
"contractor_id": task.contractor_id,
"job_board_id": task.job_board_id,
"acceptance_status_id": task.acceptance_status_id,
"taskId": task.task_id,
"publickey": el.publickey
}
task.accept_url = "https://captiontracker.retool.com/embedded/public/d4d83a21-4d82-8a74-6d80532a625c#i=" + btoa(JSON.stringify(url))
url.action = "reject"
task.reject_url = "https://captiontracker.retool.com/embedded/public/d4d83a21-4d82-8a74-6d80532a625c#i=" + btoa(JSON.stringify(url))
task.private_post = task.acceptance_status_id === 2
})
//return
rv = await restSendOneEmail.trigger({
additionalScope: {
to: el.email,
from: "brad@mathews-lowcode.com",
template: "solitsheet",
hbData: el
}})
if (rv?.id) {
data[i].tasks.forEach(task => {
ids.push({job_board_id: task.job_board_id, job_solit_sent: 1})
})
} else {
el.error = restSendOneEmail.data.message
fails.push(el)
}
}
}
if (ids.length > 0) {
qryUpdateSolitSendStatus.trigger({
additionalScope: {
data: ids
}})
}
if (fails.length > 0) {
emailFails1.setValue(fails)
txtSolitSendStatus.setValue(`##### There were error sending emails:`)
} else {
txtSolitSendStatus.setHidden(true)
}
This is what is translates to in Workflows, and I had to customize some boilerplate code as well (How to do an action based on the results of each REST call in a loop - #3 by bradlymathews):
This seems way too complex! It took me twice as long to make this workflow as it took to do the original JS query. Now much of this time is still climbing the learning curve, but still!
For very simple things Workflows is probably pretty nice, but it fails to scale in complexity pretty quickly. It also fails to take much advantage of the core Retool dev environment.
What would have been far easier would be to take the original js and sql queries and wrap a cron or webhook around them. This would look more like a module: inputs, outputs, queries, temp vars and all that, just without the UI. That would be far more powerful, just as easy to use as the rest of Retool and more familiar.
I will still look for applicable use cases going forward as I know it does have some utility, but for now I still need to use Azure functions for most of what Workflows was supposed to handle.