I have a text variable which will contain error messages or will be "".
If it is null "" I need to set a boolean variable called InputValid to True
It the text variable contains anything I need to set InputValid to False
The text variable has been created by a number of assigns using boolean variables linked to input boxes.
That all works.
The final step is to decide whether to show this error message or another message.
To do this the text needs to be checked if it contains any messages or is null.
In an Assign widget I used the following
If(TextVarMessage="",InputValid=True,InputValid=False)
Oddly, this does not change the value of the boolean InputValid
Instead it places the text "True" or "False" in the TextVarMessage variable.
I also tried
If((Length(TextVarMessage)<1),InputValid=True,InputValid=False)
and that behaved the same way - putting the result in the Text variable instead of assigning the booleans.
An hour of searching online shows nothing.
I am confused
After posting the question I thought of an idea.
Instead of trying to test & assign within the one assign widget...
I put an IF widget to test TextVar = "" and that branches to allow either the built error message to be displayed or the success message.
It worked.
It is unfortunate that I could not find anything online explaining the syntax of expressions within the Assign Widget. So I assumed it would alow things that it doesn't seem to allow.
I hope this may be of use to other beginners.
Hii Greg Adams,
if you want to assign a value in a single assignment using the if condition, this could be a way to do that.
Please let me know if it works.
Thanks,
Adeeb Alam
Adeeb,
That's bad advice. You should, in general never have an If that returns True and False, as that's superfluous: the condition itself already does that. So in your case, you should just assign 'TextVarMessage = ""' to InputValid!
Hi Adeeb,
The aim is to assign the true/false to a variable. It seems that this cannot be done in the expression formula.
It has to be done with an IF widget in the event logic not in an ASSIGN widget.
Unfortunately, the many hours of training lessons that I have been through didn't explain the syntax/use of expressions within an ASSIGN widget.
Thank you for your reply.
Kilian,
You are right i just noticed that (textvar = "") itself returns a boolean value so there is no need of a extra if condition thats returns true or false.
Hi Greg,
Not sure what you mean by "the syntax/use of expressions within an assign widget". They work exactly the same as in any other programming language, except that there's no explicit "=" or ":=" as in high-code languages like C++ and Java. There's two input boxes: the first for the variable that's going to be assigned, and the second where the expression is. And an expression is conceptually the same as in other languages. Whatever you put there must evaluate to a value that's compatible with the variable. And I'm pretty sure that somewhere in the training material there's explained how to use the "If" function (well, it's sort of a function, only one expression is evaluated, as opposed to "normal" functions).
I want to focus on this part you wrote:
It seems you have a fundamental misunderstanding of how an If works, and how boolean variables work. An If has three parts: the condition, the result in case the condition is true, and the result the condition if false. The true/false results must be of the same type (or one convertible to the type of the other), and if you assign that result to a variable, another conversion may take place.
In your case above, the condition is "TextVarMessage = """. So if TextVarMessage is empty, the result value of the If is "InputValid = True", otherwise the value is "InputValid = False". Now I think that you have a language like C/C++/C#/Java in mind, where the parts of an If are statements that are executed when the condition is True or False. However, in OutSystems, the If is a function, so it outputs a value, comparable to the C/C#/C++/Java "? :" operator. So looking at your If, "InputValid = True" isn't an assignment, it's the result. A result that consists of a condition itself, that will result in a boolean (True/False). So if TextVarMessage is empty, the result of the If will be True if InputValid is True, otherwise it will be False. And if TextVarMessage is not empty, the result of the If will be True if InputValid is False, and False otherwise. Since it is then assigned to TextVarMessage, which is a Text, the texts "True" or "False" will be put in TextVarMessage. That is not odd in the slightest, but exactly as it should.
Hi Kilian
You are right that I had a fundamental misunderstanding.
I had forgotten that the ASSIGN widget is connected to one variable. That is the variable that is going to receive the value.
I was thinking that I was in a procedure called ASSIGN & my task was to assign values to whichever variables I wanted.
The thing I actually needed to do was put this choice in an IF widget & just use the expression
TextVarMessage=""
and then do whatever needed to be done after that.
Thank you for your detailed reply
Great to hear you get it now :). Happy coding!