How to build a ValueList using a Stored Calc

I have a field in the customers table called “cTest” (text).

I have created a calc called “cTest” (text) with the following method:

var x = fName + " " + lName;
return x;

No problem, the calc field shows the correct fullname on the form. Also, I can see in the DataProviders dialog that the calc is supposed to be stored in the matching table field (shows the stored checkmark)

However, I want to use this calculated value to create a value list for a combo field on an order form, which is related to the customer table. The idea is that the user can select the customer name from the combo, so I can use it to build a new SQL query that will select only the orders for that customer.

So, I realize that you can not use a calc field for a value list, but I thought I could use the field that the calc is supposed to be stored in, but looking at the values, I see the table has NULL for all rows in this column. Hence, my value list has nothing to select.

I realize it must have something to do with the fact that the calcs do not get evaluated and stored immediately, but how do I go about this?

If you create a stored calculation Servoy will NOT calculate this for every record that is already in the table (imagine you create a calc on a table with 10 million records and Servoy goes over all of them). If you want existing data to be calculated, you can use databaseManager.recalculate().

Okay, thanks for that. The databasManager.recalculate(foundset) function was what I was looking for. Now my database has the calculated text value in the columns for all rows.

However, I did notice that math calculations did not update. I have a field called cTest which returns 1 + 2, and this the recalc funtion did not update in the table. For all rows the column is still null.

I verified that the cTest field is an integer, and the field in the table is of the same type, and that the store checkmark is on (field name matched).

I have never seen a problem in that area. Does the result value show in a form? Can you post the code of the calculation?

Code is for a simple test.

var x = 1 + 2;
return x;

The calc field displays the number 3 on the form. The table, even after running databaseManager.recalculate(foundset) has null as the values in the field (verified using an external SQL query tool). I made certain I had all the records before running the recalc, and as I said, the cTestText field is calculated and stored fine.

I’m beginning to think I have a problem with my Servoy installation, as I noticed another odd thing.

If I go to place a field on the form, the Property Editor dialog shows me the cTest calc field (integer) and the cTestText calc field (text), but only shows the matching cTest table storage field and does not show the cTestText table storage field. Now I didn’t want to use the field on the form, just testing, and observed that it was missing. I looked in my external SQL tool, and the cTestText field is there, and it has the calculated field value (lName + fName), but Servoy does not see it.

I have restarted everything multiple times.

Gary,

I could not reproduce the problem as you described.

Do you see the same behavior in a fresh install of Servoy? Also please try the latest 3.1 version (3.1.6)
If you do, please create a small sample solution and create a case in our support system

http://forum.servoy.com/viewtopic.php?t=6789

Rob