first_notempty for boolean?

Options
Hello, so I want to create a simple way for updating my entries and ignoring the empty variables, the easiest way I found is by using first_notempty

The problem comes when trying to do it for the boolean fields, so for them I tried using first_notnull instead which seemed a very logical option,
BUT in this case I have a records "banned" column set to "true"
[5zy8HGE[1].png]

Then I make a request  using "banned":"" 
(which in theory should simply not update the field)

And then it changes the entry to FALSE

Really not sure, so it it first_notnull not the appropriate function to use here?

Thank you 👌
[Dxi8BZW[1].png]
[wsR8Z6q[1].png]

Comments

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options
    Hey, Tomas. The "set_ifnotempty" filter is what you want here. Video posted below. Also, just to explain a little bit -- because you're using a boolean, there is no "null" or "empty" value for this -- it can only be true or false.
    
  • tomas randomas
    Options
     Thanks for the reply Chris! 
    A few questions,   first_notempty - I don't really understand how that one works, but  set_ifnotempty  seems pretty straightforward, set the value if the variable is not empty, so I could just use  set_ifnotempty  for updating all the fields, not just my boolean fields, right?

    Using  set_ifnotempty  worked when I passed the empty field - it kept the "true" for that field, and when updating from 'false' to 'true' it works!
    But when I try to update the record to 'false' - it doesn't work (just like it's description  says)..
    I understand that there definitely is a good logical explanation from the programmers point, but I just don't understand. 
    Please tell me how would you work in such case, if we want to be able to update the database records (setting true/false, making it empty, setting the data sometimes) 
    Would you set up a separate API endpoint for updating the record to 'false'? 🤷‍♂️

     
  • Sourabh Jain
    Options
    
    Not exactly the same problem, but I was also facing difficulty in setting boolean values. I wanted to have one API where input boolean values can be blank, null, true, or false.
    And I didn't want to update the existing value when blank/null was coming as input.

    For adding a new record it was a simple solution to use set_ifnotnull instead of set_ifnotempty.
    Editing record's with boolean values was a little tricky.  helped me with a solution and also made a nice loom video about it. You can also check it out. 
    
  • dchmiele
    dchmiele Member
    Options

    Hi guys, where are the links to videos referred to above? I can't see them anywhere in this post?

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hi @dchmiele - we recently migrated community platforms and unfortunately we were unable to bring over attachments and links... here's the video:


  • Jarryd Christensen
    Options

    Running into the same issue when trying to work with booleans and updating a record. Trying to create one endpoint that can handle multiple edit/update scenarios, the set_ifnotempy and first_notempty work for everything except booleans as it seems "false" is considered "empty", so when trying to change a "true" value to "false" you can't differentiate between an actual false value sent or when that field isn't included.

    For example if I have a field "reviewed" and set it to "true" and try to then send "false" it get's ignored as empty and doesn't update. Is this a bug as false isn't referenced as being considered empty in any of the documentation.

    Any help would be greatly appreciated as i'm going in circles with how to do it.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hi @Jarryd Christensen if you notice @Chris Coleman's comment near the top, set_ifnotempty will not work for booleans since they can only be true or false

  • Jarryd Christensen
    Options

    @Michael Udinski that makes sense and figured that when testing, but first_notempty doesn't work either as false is being considered empty in Xano and not an actual "false" boolean value. I also can't set a conditional as both passing an actual "false" value and not inculding the field are considered the same.

    If you can suggest a way to update a field from true to false while also ignoring when the field value isn't passed that would be greatly appreciated as it seems like it should be a simple.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    @Jarryd Christensen you need to use a conditional IF…THEN…ELSE… function for this use case because it has the ability to distinguish between == and ===. The latter being an exact match and the former being a flexible one. Here's how:

  • Jarryd Christensen
    Options

    @Michael Udinski thanks for the video, that clears up alot! I was using the databse linked field, but forgot you can create a new field to use instead.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Great to hear :)

  • alpha
    alpha Member
    Options

    @Michael Udinski Hi, thanks for the LOOM. I tried to replicate the boolean parameter (called Active for your), but run into an error as the name is already used, how did you achieve to duplicate that parameter with the same name on your side?

  • SasanMahdian
    Options

    @alpha did you get this sorted ? i cannot add a new input with and existing name. I'm running like a headless chicken around this issue for hours. Please help.

  • SasanMahdian
    Options

    @Chris Coleman can you please help on this ? many thanks

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hi @SasanMahdian can you clarify what you are trying to do? You can't have two inputs with the same name if this is what you're trying to achieve.

  • SasanMahdian
    SasanMahdian Member
    edited September 2023
    Options

    I just try to handle null, not set boolean input to set a boolean in a table as per the discussion above.
    I can see in the loom video that there are two "active" booleans, one is a tableref but disactivated and another one created by the user.

    I use a switch / toggle in front end that sends null for false, and true. when other properties of the table are modified in front end, the boolean input is not set.

    So for it is just impossible for me to just change the boolan property in my table, when just the switch is turn on or off.

    first_not_empty works only for non booleans.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Correct, booleans are not supported by the conditional set filters because empty, false, null, and 0 are all considered empty values.

    You'd need to use a conditional function (IF… THEN… ELSE) to define IF input === null. THEN update as null, ELSE update with input value. (The triple === signifies an exact match so make sure to use that instead of == which is a flexible match)

  • SasanMahdian
    Options

    @Michael Udinski I did exactly as you mentioned earlier today. It did not work with the table reference bool as input. So i tried to create another input (by hiding the other one from the API) as shown in the loom video. But i cannot create another input with the same name. The same issue was highlited by @alpha in this conversation.

    This is the first time, but i need help on this.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    I would remove the database link or name the new input a different name

  • SasanMahdian
    Options

    I Will try this but as the table have +15 fields its not Practical. Thé complexity increases by number of booleans.

    I think Xano it Would be Great if xano could implement isset php Function too. Its à bit à Random behavour.

  • M_Zayaan_Waqar
    M_Zayaan_Waqar Member
    edited September 2023
    Options

    Hi @SasanMahdian did you figured it out that how can you overgo this issue when you are using multiple bool variables?