568
Views
12
Comments
Solved
Convert string to Boolean
Application Type
Reactive
Service Studio Version
11.14.16 (Build 60354)

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.

2023-04-19 18-38-51
Bas de Jong
Solution

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

2023-04-19 18-38-51
Bas de Jong

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

2023-08-28 07-00-10
Paulo Torres
Champion

You can create your function.

If(Input = "True", True, False)

And this function will return a boolean parameter.

Regards

2023-04-19 18-38-51
Bas de Jong

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.

2023-08-28 07-00-10
Paulo Torres
Champion

He can use lower or upper like you told. Easy to solve :)

2021-09-06 15-09-53
Dorine Boudry
 
MVP

i think you should reconsider your UI, why let the user type this instead of offering for example a switch or checkbox widget ???

2025-06-06 07-35-05
Akmal Hakeem

truly sorry, I forgot to mentioned that the string input is received using radio button not input widget. 

2023-08-28 07-00-10
Paulo Torres
Champion

You can set Boolean in Radio Button as well

2023-04-19 18-38-51
Bas de Jong

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.

2025-06-06 07-35-05
Akmal Hakeem

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.

2023-04-19 18-38-51
Bas de Jong
Solution

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

2025-06-06 07-35-05
Akmal Hakeem

Thank you so much! its working like charm.

Thanks again for helping newbie like me =). Hadn't thought to implement it that way.

2023-04-19 18-38-51
Bas de Jong
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.