Conditional filters, first_notempty and zero values

Options

I am using conditional filters to update a record with partial values using an API call (https://www.youtube.com/watch?v=WvOlaXmoq5o)

This is working as expected, but I am running into a problem when I attempt to update the record with a zero value. Where I am attempting to write a zero value, the associated field in Xano is not being updated. If I change first_notempty to first_notnull then the zero value gets written, but if I don't include the field in the payload the Xano field is cleared/reset to zero (which defeats the purpose of a partial update).

I am looking for a solution where in one API endpoint:

  • Zero values from the API call are written
  • Non-zero values from the API call are written
  • If fields are not sent as part of the API call, the existing values should persist

I am using WeWeb as my front-end.

Screenshots from Xano and WeWeb attached

Thanks in advance!

Answers

  • ilan
    ilan Member
    Options

    Just worked out the solution and wanted to post it here in case others are experiencing the same problem.

    By default, fields are set to 'not nullable'. Whenever a null value was being sent from the API, the field value was being set to zero. Once I changed this for all non-ID fields in the table and used the first_notnull approach from the video above, everything worked as expected.

    At first I missed the 'not nullable' variable because it isn't in the field settings. To find it, click on the relevant field name in the relevant table in the Database and choose the 'Change type' option from the dropdown.

  • stephane
    stephane Member
    Options

    @ilan you saved my butt thanks!

    set_ifnotnull + nullable to yes worked in all cases for me :
    PATCH

    { article_id: 0 } ⇒ reset the article_id to 0
    { article_id: 100 } ⇒ reset the article_id to 100
    {} ⇒ leave the article at 100


    Cheers,

  • stephane
    stephane Member
    Options

    @ilan today I noticed that what we did is not working for array of ids.

    PATCH

    { category_ids: [1,2,3] } ⇒ sets the categories to [1,2,3]
    { } ⇒ sets the categories to [] // expecting to have [1,2,3]…

    Have you figured out something for this case ?

    Cheers,

  • ilan
    ilan Member
    Options

    Hey @stephane, unfortunately not. I'm about as novice a Xano user as you could find and once I got a solution that worked for me I stopped looking.

    Hopefully someone else in the community can help!

  • stephane
    stephane Member
    Options

    thank you @ilan I will keep investigating then :)

    @Ray Deck @Chris Coleman any thoughts?

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    There are a couple of moving parts here, but I would start with inputs and outputs. Is category_ids allowed to become blank? How is it sent from weweb? You can check the latter by looking at the request history. If the value is not coming in, you can check to make sure the input is nullable on the Xano side and that it is not set to a default value of a blank array.

  • arturosanz
    arturosanz Member ✭✭
    Options

    The first_notempty filter is really quite dangerous. Not only it considers the string "" empty, which is correct, but also the string "0", which is clearly not empty. This doesn't make sense at all. See the screenshots below.

    1. "" string → considers it emtpy (correct)

    2. "0" string → considers it empty (incorrect)

    3. "00" string → considers it not empty (correct)