Hi All,
I have had a problem for a while and there has been no feedback if I asked questions in related topics, so I figured I’ll create a new one.
-
The problem is that we set autoSave to false on startup and our stored calculations never get saved.
We never execute databaseManager.saveData() without passing it a particular record or foundset, so there’s no chance for uncontrolled data changes like that to be saved.
-
A bigger problem is that when a stored calculation is executed by Servoy the foundset goes in editing mode and I cannot perform .find() on it. This breaks a lot of things that are supposed to work.
Also, I cannot capture the moment when the data change happens as onRecordEditStart() is not fired, so I cannot do anything about it.
How do I manage those changes?
Cheers,
Maria
I think I don’tunderstand the problems you are describing:
- autosave false requires you to save, so what is your real question?
- do a save before a find, to be sure finding correct data
Maria,
What are you trying to accomplish exactly?
Why do you want stored calcs to be saved but not (apparently) manually entered data that triggered the calc in the first place (or are you using system values like current dates?)?
What is the purpose of these calcs? Perhaps there is a better way of doing this.
Jan Blok:
I think I don’tunderstand the problems you are describing:
- autosave false requires you to save, so what is your real question?
- do a save before a find, to be sure finding correct data
- Jan, we use multiple floating windows and keep track of unsaved records in each of them separately.
This means we cannot just save everything with databaseManager.saveData().
The records that are being edited are stored in each window and when the user clicks ‘Save’ or ‘Cancel’ - only records that belong to that window are saved/cancelled, I loop through them.
How do I know which records the user is editing? - I have a function in onRecordEditStart() that grabs the edited record and stores it in a variable in this window. I essentially control every record that is being edited in the application.
But onRecordEditStart() is not fired when a stored calculation is recalculated by Servoy, so I cannot store the record with a recalculated value anywhere to save/cancel it later. As a result, unless the user changes other data in that record (which they may not), there is no way for me to save it - my mechanism is simply unaware changes in the record.
- A save before find() is not possible for the reason above - the application is unaware of where the edited records belong. The current window where find() is supposed to be executed does not have the recalculated records in its “changed records” storage because it was unable to capture the data change. A global save is not possible as well, because other windows have their own data environment and the user might want to cancel them later.
I hope I made it clearer.
Cheers,
Maria
ROCLASI:
Maria,
What are you trying to accomplish exactly?
Why do you want stored calcs to be saved but not (apparently) manually entered data that triggered the calc in the first place (or are you using system values like current dates?)?
What is the purpose of these calcs? Perhaps there is a better way of doing this.
Hi Robert,
See, I have a stored calc in my customers table that depends on a value from invoices table (the calculation is stored to make reporting easier, and there is a number of stored calcs in different tables, it’s not just a couple of them).
So in a scenario where the user logs in, opens invoices, changes something, saves and logs out, the calc in customers is untouched and not yet recalculated.
However, when the user logs in again, or a different user logs in, or same user just opens the customers module in a table view with 20 records on their screen, and they all display that stored calc in the grid - the calc will be recalculated at this point.
As a result, the user has not changed anything but I have 20 edited records in my application and I am not aware of them.
If the user did not have other windows open, that’s fine, I can save them. But what if the user already had three windows open and has edited a job, a product and an employee? There will be more than 20 records edited in my app. As the user edits jobs, products, etc, I keep track of where those records belong, I know that if the user clicks ‘Save’ in the jobs window then I need to save the job and related stuff only in that window.
But I have no idea where my 20 customer records belong - I basically do not know they have been changed. So I can neither save, nor cancel them.
I understand it all sounds pretty complicated but so is our application.
I appreciate if you could help make it simpler.
Cheers,
Maria
but you won’t have any idea which window it really is that touches the calculations…
Those calculations are not triggered by a user in one window. but can be triggered in multiply windows or just in a script somewhere…
A quick thing that i can come up with is that you compare all real user edited records (that you store in any window object) with the databaseManager.getEditedRecords()
so that you can extract a list of records that where “done by the system”
jcompagner:
but you won’t have any idea which window it really is that touches the calculations…
Those calculations are not triggered by a user in one window. but can be triggered in multiply windows or just in a script somewhere…
Well, Johan, as of the moment if I capture onRecordEditStart it has the JSEvent passed as the first parameter from which I know which window caused the data change.
If onRecordEditStart was triggered when a calc is recalculated for a record then I would know where this event comes from I suppose.
Or at least I could store those records in a separate object and manage them accordingly.
jcompagner:
A quick thing that i can come up with is that you compare all real user edited records (that you store in any window object) with the databaseManager.getEditedRecords()
so that you can extract a list of records that where “done by the system”
Yes, that was my last resort solution, Johan.
It will add overhead processing in all places where I will have to run the check and may cause data integrity issues.
Cheers,
Maria
Currently we do that on purpose to not fire it, because if it is just a calc, we just call quickly start and stop
But yes if you block the stop then it won’t be saved so it will keep hanging around.
But relying on editRecordStart for this could be quite hard to catch everything
Because in scripting or in loading or when you display stuff in a portal, then onRecorEditStart doesn’t have to be called
onRecordEditStart is only called for records that belong to a visible forms foundset, so invisible forms don’t get that event
or records of foundsets not yet attached to a form will not be registered at all.
What happens if you have 2 windows open that show the same foundset (as main or in a tabpanel)
and in 1 window the user start the edit? Because then the second window also gets the edit event…
jcompagner:
Currently we do that on purpose to not fire it, because if it is just a calc, we just call quickly start and stop
But yes if you block the stop then it won’t be saved so it will keep hanging around.
But relying on editRecordStart for this could be quite hard to catch everything
Because in scripting or in loading or when you display stuff in a portal, then onRecorEditStart doesn’t have to be called
onRecordEditStart is only called for records that belong to a visible forms foundset, so invisible forms don’t get that event
or records of foundsets not yet attached to a form will not be registered at all.
What happens if you have 2 windows open that show the same foundset (as main or in a tabpanel)
and in 1 window the user start the edit? Because then the second window also gets the edit event…
That is not exactly the case, Johan.
If the user has two windows open with the same record and starts to edit it in window 1 then onRecordEditStart fires in window 1 and I catch the record right away.
In the meantime window 2 will get the changes the user is entering, yes, but no events are fired in that other window, and it’s fine.
Well, I understand it is something that we will have to work around. Not sure how efficient it will be.
Cheers,
Maria
if you really display the same foundset somewhere at the same time in 2 windows
And you start an edit in 1 window on the record thats also in the other window then both windows should get a record edit start event! If that is not the case then thats a bug…
jcompagner:
if you really display the same foundset somewhere at the same time in 2 windows
And you start an edit in 1 window on the record thats also in the other window then both windows should get a record edit start event! If that is not the case then thats a bug…
All forms on tabs within one window are linked through a synchronizing relation - both ends of the relation are the same table but there are no keys in it.
So within one window all forms based on the same table get onRecordEditStart.
When I pop a window, I duplicate the default foundset of a table and load it in the window.
When I pop another window, again, I duplicate the default foundset and load it in.
This way, at any time, I can have more than one window displaying different records from the same table in the same form, I can select a record in window 1 but onRecordSelection won’t be triggered in window 2 - because foundsets are synchronized only within a single window.
This is why onRecordEditStart is not fired in the other window, I’m pretty happy with it though ![Very Happy :D]()
Cheers,
Maria