Disable a button if a query returns true

Hello, I want to disable a button if a query returns a set value. For example I want to set to dead only if a person is alive. or the other way round if somebody did it by mistake.

think i am nearly there, but not quite.
I have set up a query which is as follows (called CheckIfAlive)
select true as alive from table where deceased = 'true' and id = {{table2.selectedRow.data.id}}

this returns true if the entity is deceased, thus I want the button enabled.

In the button property "disabled" I have

its always disabled, its not working correctly, can you show me where I am going wrong? many thanks

A little tough to follow but ...
User a ternary operator in the disabled field
{{CheckIfAlive.data.alive === 'deceased' ? true:false}}

Yeah, you can use a ternary like Scott said.

But also, when trying to get a boolean value from comparison and checking if equal, in javascript use the loosely equal "==" or strictly equal "===" comparisons. The single "=" is for assignment.

{{CheckIfAlive.data.alive}} == false or {{CheckIfAlive.data.alive}} === false

Thanks for the input guys, thats my lack of java script knowledge I guess, i am a SQL man!
I tried what you suggest in the following flavours, but it does not disable when i would like.
{{CheckIfAlive.data === false}}
{{CheckIfAlive.data == false}}
{{CheckIfAlive.data === 'false'}}
{{CheckIfAlive.data}} == false
{{CheckIfAlive.data}} === false
{{CheckIfAlive.data}} === 'false'

I feel this is just something small and silly I am not doing...but i can't crack it..
Any help appreciated.

In the original post wasn't it {{CheckIfAlive.data.alive}} and not just {{CheckIfAlive.data}} you were referencing?

If you have returned data and {{CheckIfAlive.data}} has data, that will not evaluate to false. Which I'm sure is not what you want to check anyway, as you appear to be wanting to check if someone is alive, not just if the data exists.

Hey Shane, yes sorry your correct....I didnt reference the column ! let me go back and check that.
Check the data exists essentially tells me if a person is deceased or not. Again you spark a good point, I am not sure its returns false if there is no deceased. I will refine the query to give me a different value, and again try that. I will come back. Thanks

@shane_d_gray Thank you, your prompt sparked my brain to actually work!
I think the issue was with the SQL query I was using. Sure there are other ways to do this, but this is how I did it and it seems to work (although query seems to be slow....even though it should be using a primary key index, but that's a different issue)

So I did the query this way
select count(*) as dead from table where deceased = 'true' and id = {{table2.selectedRow.data.id}}

This returns 0 is the entity is alive and 1 is entity is dead

I then did this in the button (thanks to your education on ==)

the button is now only selectable if the entity is dead. Which is exactly what i wanted.

thank you. I have a new arrow in my arsenal now.

1 Like

In addition...I found a more efficient way to do it, since I am already displaying the record in my form, I simply reference the deceased column rather then running another DB query. Same result but fast response as no additional query required.

So I changed the disabled property of the button to be {{table2.selectedRow.data.deceased==false}}

Wonderful, I'm happy you were able to get it to work how you want!