onRecordEditStart/Stop

Questions, tips and tricks and techniques for scripting in Servoy

onRecordEditStart/Stop

Postby maria » Wed Feb 16, 2011 2:50 am

Hi All,

I'm having questions coming up now and then about these two events, so perhaps I'll keep them in one topic..

There is a form with a related tab on it.
When I click in the tab's field onRecordEditStart is fired and I execute databaseManager.setAutoSave(false);
I type some text in the field and without tabbing out click on my 'cancel' button which executes databaseManager.rollbackEditedRecords().
The result is weird: first time I do it - the text stays in the field. If I click in the field again, onRecordEditStart executes again and without typing anything I click 'cancel' again, only then the changes are rollbacked.
(In this little test I never turn autoSave to true)

How does it work? :?

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onRecordEditStart/Stop

Postby maria » Mon Feb 21, 2011 3:18 am

Another question: why do I see all my foundset records in databaseManager.getEditedRecords() when onRecordEditStart is triggered?
The event is triggered after I add one more record by controller.newRecord().

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onRecordEditStart/Stop

Postby maria » Mon Feb 21, 2011 3:33 am

One more please:
databaseManager.getFailedRecords() never returns anything even if databaseManager.saveData() returns false and databaseManager.getEditedRecords() has an array of edited records with changed data.

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onRecordEditStart/Stop

Postby jcompagner » Wed Mar 02, 2011 2:17 pm

can you create case with a sample for you first point?

You shouldn't get all yur records back from a foundset when you call getEditedRecords() only the records that are touched/new
So you are saying that if your foundset had 1000 records they are all returned? that sounds very weird to me

about the failedrecords: do you have anything in the log? does servoy send out any update statements? Or do you have a datachange event on a field or table events that return false that blocks the save because of invalid data?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: onRecordEditStart/Stop

Postby maria » Fri Mar 04, 2011 1:24 am

jcompagner wrote:can you create case with a sample for you first point?

You shouldn't get all yur records back from a foundset when you call getEditedRecords() only the records that are touched/new
So you are saying that if your foundset had 1000 records they are all returned? that sounds very weird to me

about the failedrecords: do you have anything in the log? does servoy send out any update statements? Or do you have a datachange event on a field or table events that return false that blocks the save because of invalid data?


I'll attempt to reproduce the first issue in a sample solution.

getEditedRecords() really returns related records, the number of records in the foundset just happened to be the same, so that one was false alarm, sorry.

Thanks for the questions, Johan. I'll check what my answers are and might be able to figure it out from there...

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onRecordEditStart/Stop

Postby maria » Wed Aug 17, 2011 7:21 am

Hi guys,

I came across an issue today. It appears that onRecordEditStart() is fired when a field acquires focus as well as when a dataprovider of a form is changed programmatically.
However, when a dataprovider is changed through a relation, onRecordEditStart() is not executed.

For example, a form is based on the customer table and I change the customer name (same table) in the code. Then onRecordEditStart() is called.
But if I code customer_to_contact.contactname = "blah", the the even is not fired.

Any thoughts on why not and whether it's a bug or expected behaviour (Servoy 6)?
I absolutely need to fire that event whenever any changes are made to data in the solution code.

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onRecordEditStart/Stop

Postby jcompagner » Wed Aug 17, 2011 11:44 am

this is how servoy works,

If you start an edit in the ui, we know exactly that you clicked in the ui, and then the record edit start will always be called so also for the main parent record if you would trigger it on a related field.

Now if you touch a record in the scripting, the ui (controller) listens to that an if it is its main record it will also fire.
But if it is for him a random other record (he really doesn't know that that specific record is also used somewhere) then we don't fire.

The easiest way, to a possible fix for this, is never to call that edit start event on a record that is touched through scripting, problem is that we then could break stuff people are depending on, so thats not really a choice.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: onRecordEditStart/Stop

Postby maria » Thu Aug 18, 2011 3:40 am

jcompagner wrote:this is how servoy works,

If you start an edit in the ui, we know exactly that you clicked in the ui, and then the record edit start will always be called so also for the main parent record if you would trigger it on a related field.

Now if you touch a record in the scripting, the ui (controller) listens to that an if it is its main record it will also fire.
But if it is for him a random other record (he really doesn't know that that specific record is also used somewhere) then we don't fire.

The easiest way, to a possible fix for this, is never to call that edit start event on a record that is touched through scripting, problem is that we then could break stuff people are depending on, so thats not really a choice.


Ok, there is a scenario where the user clicks on a 'search' button and a screen pops up where they select a record and click the 'select' button that has code behind it that changes a related record in the foundset. This is where the data change happens and my toolbar method switches the save/cancel buttons. This usually happens in onRecordEditStart.

As long as the record is accessed through a relation, the onRecordEditStart is not fired.
I could run the same method in onElementFocusGained but it is also not fired on labels and buttons (surprisingly).

Looks like there is no way to capture the change of data and I have to call my toolbar method explicitly in this sort of scenario. Am I correct?

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onRecordEditStart/Stop

Postby jcompagner » Thu Aug 18, 2011 9:39 am

maria wrote:Looks like there is no way to capture the change of data and I have to call my toolbar method explicitly in this sort of scenario. Am I correct?


I think if you place the related data no through a related field with a relation.column dataprovider but you place everything of that relation on a related tabpanel
then the form in the tabpanel would get a onrecordeditstart.

Else i think there is no other place
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: onRecordEditStart/Stop

Postby maria » Fri Aug 19, 2011 3:27 am

jcompagner wrote:
maria wrote:Looks like there is no way to capture the change of data and I have to call my toolbar method explicitly in this sort of scenario. Am I correct?


I think if you place the related data no through a related field with a relation.column dataprovider but you place everything of that relation on a related tabpanel
then the form in the tabpanel would get a onrecordeditstart.

Else i think there is no other place


Johan, we manipulate data in the code quite a lot and there may not be a corresponding field on the form at all, so unfortunately tabpanels are not a suitable solution.

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onRecordEditStart/Stop

Postby jcompagner » Fri Aug 19, 2011 1:52 pm

then i don't get it completely, if the data that is changed is not on the ui/form?
why do you need to have that event?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: onRecordEditStart/Stop

Postby maria » Tue Aug 23, 2011 5:46 am

jcompagner wrote:then i don't get it completely, if the data that is changed is not on the ui/form?
why do you need to have that event?


Ok. For example, I'm adding a contact to my customer record. The contact details are nowhere on the customer form, so I add the contact record in the code (add or change).
And that is when I need to know that the record was added/changed (I think if I add it, then onRecordEditStart() is fired but it does not execute not on data change).
Because we have multiple windows in our application and need to keep track of all edited records for each particular window - we need to know when any change is made.
I hope that clears my point a bit.

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onRecordEditStart/Stop

Postby maria » Tue Aug 23, 2011 8:23 am

I just came across another problem.
There is a modal form in my solution that causes all unsaved records to commit when it's closed, and I can't figure out what exactly causes the commit.

I thought onRecordEditStop was called and returned true which saved records but it returns false.
Nothing in the code (I debugged, doublechecked, triplechecked) commits records.

What happens is I bring up the modal form when there are already edited records in databaseManager.getEditedRecords(), then do something on that form that adds more edited records in memory (I also tested without running code in the modal window, just pop it and then close it right away).
Then I close the modal form and the first event that is called is onRecordSelection(). At that point already my edited records are empty, I assume some event committed them.
What can it be?
onRecordSelection fires before onHide, before onRecordEditStop and I can't think what else may be running before it but after I close the form (close by clicking the 'x' in the top right).
Please help.

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney

Re: onRecordEditStart/Stop

Postby jcompagner » Tue Aug 23, 2011 11:37 am

If you close a dialog or what ever then it can be that a commitData()/stopEdit() is executed by servoy so that autosave does it work.

If you don't want that then you just have to disable autosave and only save at places where you want.

that onRecordEditStart/Stop i still don't get you will not get events on forms from records from other tables then that form is build on.

so if you save data then onRecordEditStop is only called on the visible form for records of that form.
Related data records are not going through that. Especially related records that are not even shown on that form.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: onRecordEditStart/Stop

Postby maria » Wed Aug 24, 2011 6:42 am

jcompagner wrote:If you close a dialog or what ever then it can be that a commitData()/stopEdit() is executed by servoy so that autosave does it work.

If you don't want that then you just have to disable autosave and only save at places where you want.

that onRecordEditStart/Stop i still don't get you will not get events on forms from records from other tables then that form is build on.

so if you save data then onRecordEditStop is only called on the visible form for records of that form.
Related data records are not going through that. Especially related records that are not even shown on that form.


I get it now, Johan.
I kind of treated onRecordEditStart as a global event that is called whenever *any* record in the solution was changed, and now I see it only works for a particular form.
Thanks a lot for the explanation.

I disabled autosave and the problem with unexpected saves is gone now, thank you.

Cheers,
Maria
maria
 
Posts: 424
Joined: Thu Apr 16, 2009 1:18 am
Location: Sydney


Return to Methods

Who is online

Users browsing this forum: No registered users and 5 guests