Greater Than Operator in field expressions


#1

I was trying to define a conditional to determine a deposit amount for a bill. If the bill is greater than $2000, the deposit is $1000. If the bill is less than $2000, then the deposit is 50% of the bill amount. Can I create this expression in the visual builder? I tried but it didnt work. the <= operator causes an error when the expression is written to the html code.
Thanks
Rick


#2

Hi, Rick (@marsalstudios)

Are you talking about doing this on the App Connect or Server Connect side?


#3

on the appconnect side, thanks.


#4

Did you convert the variable to a number?


#5

If(condition ) ? True : False

So
If(amount.value >= 2000)? 1000 : (amount.value/2)

You can use data formatter :slight_smile:


#6

Rick, hopefully this gives you some ideas. I did this by setting up two variables first: deposit_required and deposit_amount.

The deposit_required variable determines if the amount_due value is over 2000 or not:

The deposit_amount variable determines the deposit value based on the amount_due entered into the text field:

The expression used for this variable is: deposit_required.value.then(1000, amount_due.value / 2). In order for me to build this logic visually using the Data Formats window, I had to first set the deposit_required field to be of Type Boolean, since it will return true if the amount_due value entered into the text field >= 2000. Otherwise it returns false.

When it returns true it calculates the deposit amount as being 1000, if it returns false it takes the value entered into the amount_due text field and divides it by 2.

The outcome looks like this:

:sunglasses:


#7

@s.alpaslan - Nice and succinct! Unfortunately, no matter what is entered into amount.value it divides it by two instead of recognizing that amounts over 2000 have a $1000 deposit.


#8

I think that is working isn’t it?

Any amount over 2000 returns 1000
Any amount under 2000 returns 50% of the amount entered.

That is what the OP asked for right?

Why ‘unfortunately’?

s.alpasslan also pointed out it could have been written like:

<span>{{ deposit_required.value > 2000 ? 1000 : deposit_required.value / 2 }}</span>

The more solutions posted the better really as it provides more background as to how issues can be solved.


#9

@the_coder, I think you may be misunderstanding me. I wasn’t discouraging other solutions!

The steps that I shared 2 posts above worked for me, which is what you see the GIF demonstrating. Then I saw @s.alpaslan’s suggestion and tried it out but it did not work. Therefore, while I liked the simplicity of what he suggested, I commented that it was unfortunate that it was not working as expected. Perhaps I did something wrong? I’ll try it again.

The more solutions posted the better really as it provides more background as to how issues can be solved.

That sort of goes without saying, right? :slight_smile:


#10

@fatherofinvention very intereesting, thank for posting.
I like when I can reach visual solution!


#11

{{ deposit_required.value &gt; 2000 ? 1000 : (deposit_required.value / 2) }}
Is working just fine, maybe you entered it incorrectly? What was the result?


#12

Hi @Teodor, this is what was suggested right? So, I copied and pasted it and it didn’t work.

This reads a little differently to me then what @s.alpaslan suggested. I guess he was writing pseudo-code that we were supposed to convert to the proper syntax Wappler is expecting? For example, in what you posted, I don’t see If nor do I see ?, both of which were apart of the suggestion made by @s.alpaslan. Please let me know how I got this wrong so I can avoid doing it again in the future! :slight_smile:


#13

There should not be any if. ? is there however. Serhat’s code is not using correct syntax :slight_smile:
Do you see any error in the browser console?


#14

My aplogises, I thought you were talking about the solution you provided not working and not refering to s.alpaslans which does work also, so I mis-read and was confused.

Its encouraging to see as many solutions as possible by as many contributors as possible because Wappler is suffering from being not that well documented in terms of a bigger eco-system surrounding it so the only place one can get help until it grows into a bigger community and maybe off forum is here.

Its not possible for every conceivable solution to be documented by the devlopers of the product, thats really up to users to discover and uncover and push the boundaries and share workflows. That’s the only way it will grow and become easier to understand.

Edited.
I guess being more of a coder I knew what s.alpaslan was suggesting and given the right expresion it works, maybe that would not be so obvious to others however if they are just copying the code as presented.


#15

this worked great!!! thanks to all for the ideas. They were awesome. Probably another thread but is there an easy way in Wappler to insert today’s date on a form?


#16

Please check the following tutorial:


#17

how cool is that!!! There is so much value hidden in this product.

Thanks,
Rick