34
Views
8
Comments
The expression is saved as text in database and need to convert it to expression

In my application, the expression is saved as text in database. I need to convert it from Text to Expression and then evaluate that expression to get Boolean value. Depending on that Boolean value, I need to handle visibility of field on page.

Please let me know if there is any way to convert text to expression.

Thanks for help in advance.

Hi Nilam,
Which type of text you have in your table?
Is it the text "True"/"False" or something else?
You can add new attributes in your aggregate wherever needed and prepare your logic as provided in the screenshot.
Also, you can use this type of condition on the run time, if you want to hide the data in your table you can use a similar condition with the "list.current" value.

Please let me know if you have more queries.

Regards,
Anubhav

I am curious what the expression value is that you store. If it is just purely "True" or "False", why not have that as a boolean value stored?

Anyhow, if you need to check on a specific value, please don't use If(something.something, True, False)

Just use the following in the expression:

NewsPaperDistributors.Label="True"

The = evaluates the check to a True or False, no need for a wrapper If

HI @Jeroen Bindels ,
Thank you for your reply. 
The above-given condition is just an example it is not relevant to the "Newspaper distributer" table, I was just trying to answer this post by adding a new attribute in one of the existing aggregates.

Yes, we can directly compare the values to get the boolean output, the motive of my above condition is to describe the logic for a better understanding.


Regards,

I know, I used your newpaper table column names as an example, too.

Then just generically speaking:

If anything, your example could even add confusion if you type comparisons that way.
Shorter is clearer, especially in some longer if-expressions.

How is this 'for a better understanding':
If(SomeColumn="value1",True,If(OtherColumn="value2",True,False))

Clearer than this:
SomeColumn="value1" or OtherColumn="value2"

Or even worse, when you need to swap around True/False within the statements:
If(SomeColumn="value1",If(OtherColumn="value2",False,True),True)

That should definitely be:
not (SomeColumn="value1" and OtherColumn="value2")

Or:
SomeColumn<>"value1" and OtherColumn<>"value2"

All I want to say, keep it clean, readable and shorten where needed

Hi Nilam,

You can use below forge component to evaluate an expression and get the boolean output

https://www.outsystems.com/forge/component-overview/13039/expressionevaluator

This expression uses below C# code to evaluate the expression

https://learn.microsoft.com/en-us/dotnet/api/system.data.datacolumn.expression?view=net-6.0

Regards

Devendra



The main questions to answer still are:

Which expression are you saving in the database as a text value?

Why does this need to be saved in the database, is this expression per row different?

An example really helps pinpoint an actual solution.

Hello,

Thanks for reply.

We have stored expression in text field in database table. 

That text field contains expression like below -

Status.Value ="AGREED" and (Type.Value = "1" or Type.Value = "2" or Type.Value = "3" or Type.Value = "4" or Type.Value = "5" or Type = "6")

The above string is actually expression but its coming from entity's text field.

How can we convert above string into expression so that I can get result as True or False, based on that expression?


Regards,

Nilam Yadav

Is this expression different for every row, or is it something that should be able to be changed by someone?

Because otherwise, why should you need to store such an expression?

During data-fetching, or even within an aggregate, you can add an additional column, evaluate the rows against the expression to a True/False.
Or, if needed, even in the front-end (Traditional Web and Reactive).

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.