If value is .. then .. else ..

Options
Hi,

I recently started to explore Xano. But I have the following question.
We use a lot of variables. What I would like to do is a variable give a certain value depending on the value of another variable. 
Even in some cases and want to use more the one if, else, then. 
I found de conditional filter, but this is just half the solution. 

I know I can use the if statement, but that's not very handy to have al this statement in the function stack.

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    Have you looked at the custom functions? Composing can allow you more complex control flow in a more readable stack that I think you might be looking for here. 
  • Frank Wieffering
    Options
     Hi Ray, thanks for your reply! This is an option but still there will be a lot of this functions. 
    In an other no-code platform you can use the following statement:
    var:vat_include ? var:price * var:amount : round(price,2) * var:amount
    (vat_include is true or false. After '?' is the true statement, and ':' stands for else.)
    This not entirely no-code, but this is a powerful feature. And I really mis this possibility in Xano.
  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
     We are working on the next iteration of our function stack and I'm in agreement that lots of conditionals feels overwhelming. We have some good ideas on how to make it feel more light weight.

    In the meantime, you probably will be interested in the set_conditional filter. It will allow you to hide some of the logic inside a filter just as you would in your ternary operator example.

    https://docs.xano.com/working-with-data/data-type-filters/manipulation-filters/conditional-set-filters

    There is a good video in there, but I just released it doesn't go over set_conditional specifically.

    Here is a screenshot to show an example. https://mrkr.io/s/622e202ff1f12b79fe56d592/0
  • Frank Wieffering
    Options
     Thanks. nice to hear this something Xano is reconsidering. At this point I choice the if-else function instead of the set_conditional because it's too limited. (Or I'm not exactly know at this point how this exactly works 😀 )
  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
     show a screenshot of what you did and I'll give you the alternative with set_conditional.
  • Frank Wieffering
    Options
    . For my defend, I just started...
    Hereby a simple example.
    Vatinclude is a boolean.
    [CleanShot 2022-03-14 at 16.16.27.png]
  • Sean Montgomery
    Sean Montgomery Administrator

    ADMIN

    Options
    The conditional needs to be in the last parameter called conditional. Check out my screenshot. https://mrkr.io/s/622e202ff1f12b79fe56d592/0

    value = price
                 set_conditional
                    path=(keep this empty)
                    value=netprice
                    conditional=vatInclude