Basic question - only run a query if box is ticked

Hi this hopefully is a really simple question. I thought I had figured it out but i can't get it to work.

I have an app that records all our tasks. Some tasks are internal, some are client-based. Most but not all client tasks need to have their time logged. I have 2 queries... closeTask and logTask. Both work independently. I want to have a JS Query that triggers closeTask first and then if the "Log task" checkbox is ticked it runs the logTask query but i can't get it to work. This is what I have:

closeTask.trigger()
if ({{logTaskCheck.value}} ==1){
	logTask.trigger()
}

What am i doing wrong and/or is there a better way to do approach this?

In my experience, you shouldn't need the curly braces in a js query, and unless there's some nuance that I'm not aware of within js, then you can drop the == as well. I threw some console.logs in there too for grins.

This seems to work as expected within retool.

closeTask.trigger()
console.log(typeof checkbox1.value)
console.log(checkbox1.value)
if (checkbox1.value){
  logTask.trigger()
}

Edit:
This block is probably more appropriate and avoids any issue with checkbox1.value returning something other than a boolean -- probably unlikely. Using the ===.

closeTask.trigger()
console.log(typeof checkbox1.value)
console.log(checkbox1.value)
if (checkbox1.value === true){
  logTask.trigger()
}
1 Like

@matth thank you SO MUCH - you're a total legend. The solution you provided works perfectly and really helps me understand reTool a little better. It makes total sense.. as it is a javascript query you don't need to use the {{ }} which tells the system it is Javascript.

Thanks again.