Hi,
Is there a way to convert string to Boolean in OS?
Let say I receive input from user with text value of "True" or "False", I need to assign that value to variable with Boolean data type.
I know that OS has BooleanToText function, but I couldn't find ready function to convert text to Boolean.
Edit:
Sorry guys, I forgot to mentioned that the string input is received using radio button not input widget.
I use local variable with data type text for the the radio button with 2 value - "True" and "False"
To answer the question why the UI is like that because it's client's requirement.
so the text value received from the radio button have to be assign to a variable with Boolean data type before saving to DB
That is why I need to find a way to convert the string to bool before assigning it to the variable.
Ah, a common problem :-) you can fix this to use an integer, default -1 which is nothing, 0 for false, 1 for true and convert it afterwards. Or you can create a static entity with 3 values. Null, true and false and assign those to the radio buttons. In your backend convert to true/false
Just use the following:
Trim(ToLower("yourtext"))="true"
if the text is something like "true", it will return a boolean True value. In all other cases it should return False
You can create your function.
If(Input = "True", True, False)
And this function will return a boolean parameter.
Regards
Hi Paulo,
Although your answer is right, it will not take into account if true is written in lowercase, or if an accidental space is added.
Also, if you use an if-statement in the form of if(<something>,true,false) you can remove this because it has no function. Comparing a string in outystems already produces a boolean result.
He can use lower or upper like you told. Easy to solve :)
i think you should reconsider your UI, why let the user type this instead of offering for example a switch or checkbox widget ???
truly sorry, I forgot to mentioned that the string input is received using radio button not input widget.
You can set Boolean in Radio Button as well
Hi Akeem,
Your radio group containing your radio buttons can be assigned to a boolean-type variable. Then you can assign the radio buttons below to True/False boolean values. No need for conversion.
yes true, I have tried that. But it come with a problem when I use boolean with the radio button, when user start new session, the radio button prefill with default boolean value which is false.
user want the radio button to be unchecked everytime they start new session. That why I'm using the local variable.
Thank you so much! its working like charm.
Thanks again for helping newbie like me =). Hadn't thought to implement it that way.
No problem! Good luck!