Something like this:
Thanks Colin. Similar to above I have the form data and I retrieve the database data. Where I find myself puzzled with Mendix is in two areas:
1) this idea that to show the results on a page then the page needs to have an entity given to it to show the values. An entity suggests to me something stored in the database however I do not want to store these results in a database
2) where do I perform this calculation? (e.g. "Number1 from the submitted form" multiplied by "Number2 retrieved from the database") - where do I do that calculation?
Many thanks!
Hi John,
Answer to your question,
1. Do I need to store the result in the database to show it on a page?
No, you don’t need to store it. For temporary values like calculation results, use a non-persistent entity — it exists only in memory and isn’t saved to the database. You can use it on pages just like a regular entity for displaying data or forms.
Steps:
Create a non-persistent entity (e.g., ResultData) with an attribute like ResultValue (Decimal).
In your microflow, create an object of ResultData and assign the calculated value.
Use a Show Page activity and pass this object to the page.
On the page, bind the attribute (e.g., ResultValue ) in a text widget to display the result.
2. Where should I perform the calculation?
You can do the calculation directly in the microflow triggered by your form’s submit button.
Here’s a sample logic flow:
Your form captures a value (e.g.,FormInput/EnteredValue).
Retrieve the stored value from your database (e.g., StoredEntity/StoredValue).
Create a new ResultData object.
Use a Change Object activity to set the result:
$StoredEntity/StoredValue - $FormInput/EnteredValue
Pass the ResultData object to a page and display the result.
P.S: Use Colin screenshot for calculation
Thanks
Guna
Thanks so much Guna, that has been extremely helpful. Below is my microflow and the calculation is inside the Change object. I have two follow-up questions if possible:
1) on the Create ResultData object there is an error "the Value property is required for this member" - not sure what is needed in that Value box
2) On the page where I where i want to display the result I would normally bind an entity to e.g. a List View but as the entity is non-persistent it throws an error if I select Database -> My non-persistent entity
Many thanks in advance! I'm learning a lot about Mendix through this.
John
actually - i just realised Colin's image scrolls across (i couldn't see the end of it!) :-) ok we're very similar on the microflow but I notice Colin only has the Create Object whereas I have both Create Object and Change Object..
So I just moved the calculation from my Change Object to my Create Object instead and the error is gone and presumably I can now delete the Change Object.
Guna - questions above still stand though as I'd be curious to know if you use both Create and Change and have the calculation in Change what should go in the Value box of the Create
and then the question re. list view in the page also
thanks!
I will close this out. I just moved the calculation from my Change Object to my Create Object instead and the error is gone and deleted the Change Object.
In terms of displaying the non-persistent value on a Page - I had the param set in the page in the microflow and to get it to display on the Page in a browser I put a text widget inside a dataview - and then I had the context to that param that I needed.
Thanks for all the help.
The only outstanding question is: I'd be curious to know if you use both Create Object and Change Object and have the calculation in Change Object then what should go in the Value box of the Create Object?
Hi John,
Apologies for the confusion earlier. You can simply use a Create Object activity. Within that object, include an attribute for the test result and perform your calculation there for example,
$UserInput - $RetrievedData
,
Once the result is calculated and stored in the object, pass it as a parameter to the page. Use a Data View to display the result, and inside the Data View, add a Text widget that binds to the attribute where the result is stored.
Refer to the screenshot below for guidance. And that’s it your test result will be displayed on the page.
Regards
Guna
P.S. If this solution worked out for you, please go ahead and accept the answer 😊