How to store expression in local variable?
Question
Application Type
Reactive

Hi all, sorry for the newbie question but I'm stuck right now.

In a form I enter different values (decimal). From these values another value is calculated via an expression.

Now I want to save the inputs and the result of the expression in an entity. For the inputs this works. I guess that I have to write the value of the expression into a local variable to be able to assign this value to the entity when saving. Correct?

But, how do I store the value of the Expression in a local variable?

Thank you very much for your help.
Michael

Hi Michael,

I am also learning outsystems, so will try to give you a visual help how you can achieve this.

Please follow below steps to achieve:

1.Create DB:


2. Create UI with Calculated value in binded to expression like age


3. Then do this OnChange  event of any dependent Value by which you want calculation to happen

Then you can directly save the entity:



Hope this will help you.

Thanks,

CA Sunil Kaushik

Hi @Michael Guenther,

You can assign the expression value to the local variable before performing Create or update action.

Thanks, Aadhavan S

Hi Michael,

I believe that you use a client action (set is function = true) to calculate value for expression right?

In your save action: you just call the client action again (same input values as in form) then assign the result to your entity.

Hope this helps,

Khuong

Thank you for your feedback. I am still a little lost though.

My expression is calculated as follows:

GetComponentById.List.Current.Component.AContent + GetComponentById.List.Current.Component.BContent + GetComponentById.List.Current.Component.Ratio * GetComponentById.List.Current.Component.AContent

Example:
AContent = 10.0
BContent = 10,0
Ratio = 1

calculated expression value = 30,0

Now I want to save the value 30.0 in the entity "Component" under the attribute "Content".

What is the best way to do this? Thank you very much for your patience.

Are you saving this record: GetComponentById.List.Current.Component?

If so before call CreateOrUpdate (Or Save action) you should add a Assign widget and set value as follow:

GetComponentById.List.Current.Component.Content = GetComponentById.List.Current.Component.AContent + GetComponentById.List.Current.Component.BContent + GetComponentById.List.Current.Component.Ratio * GetComponentById.List.Current.Component.AContent 


Note: For better way you can add a client action (set is function = Yes) for calculation value with Input is Component Record and Output is the result of calculation.

Then you can call the function in your expression and also in Assign widget before saving the record.

Hi, Michael,

If you want to save the result in the same Entity, I guess you can make a calculated attribute under the aggregate you are fetching to store data, there you can have the same expression you want to calculate with those attribute. while saving you just need to assign the value of calculated attribute to the require attribute ,in which you want to save the value.

Hope this helps,

Mita

Hi Michael,

Rather to store expression value in variable try to bind that expression with variable and show the same calculated value in expression using that local variable and the same variable you can pass to save the value.

hope this help.

Regards,

Shoeb

Hi Michael,

Please have a look at the below oml file for your reference.

Hope this helps.

testapp.oml

Hi Michael,

I am also learning outsystems, so will try to give you a visual help how you can achieve this.

Please follow below steps to achieve:

1.Create DB:


2. Create UI with Calculated value in binded to expression like age


3. Then do this OnChange  event of any dependent Value by which you want calculation to happen

Then you can directly save the entity:



Hope this will help you.

Thanks,

CA Sunil Kaushik

Thanks for the help to all.

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