So for part 1, i think that the solution really would be to check if the return is non-null, as simple as that seems. So expanding on your example, you could do something like this:
if (txtAddTemplateName.value) { // Only execute if form is filled in.
(async () => {
const res = await qrySourceUpdate.trigger()
if (res) {
const myField = res.theField[0]
return myField
} else {
throw new Error("Query returned no data!")
}
})();
}
For part 2, I think there may actually be a bug with async/await in Retool, as what you are doing should be correct. I was able to use a Promise.resolve() to do this however:
return Promise.resolve(targetQuery.trigger({
additionalScope : {key1: moment().format("ss")}
}))