How to prevent a recordsave

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

How to prevent a recordsave

Postby Odysseus » Wed Apr 07, 2004 4:29 pm

Problem:

I have a list view with records on a table. I can click a "new record" button which triggers a form to be loaded into a dialog (showformdialog) and start a transaction

This new record has a db managed PK and an obligatory FK. When the user clicks outside a field BEFORE a FK has been entered, the db immediately throws an exception (missing foreign key).

So 2 questions:

1) Why does it try to write to the db before a committransaction is given?
2) How can I prevent the recordsave from being triggered ( I tried attaching an method with "return" in it. Doesn't make a difference).


Any insights very much appreciated
Odysseus

Citizen of Old Europe
Odysseus
 
Posts: 205
Joined: Wed Sep 10, 2003 9:34 pm
Location: Belgium

Postby Jan Aleman » Thu Apr 08, 2004 12:50 am

Best is to first set the FK.
onRecordSave can't be overriden.
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby Odysseus » Thu Apr 08, 2004 8:27 am

do you mean to set it to an arbitrary value ?
the fk_field is formatted as a table_based value list, so it is up to the user to select the appropriate fk_key value.

hmm, still puzzled...

I was thinking more in the lines of this code attached to the recordsave trigger of the form

if(!(fk_field))
{
intercept the record_save event, genre "dontpassevent"
showInfoDialogbox
}

But this is not possible ?
Does something like "dontpassevent" exists?

Thanks for any insights
Odysseus

Citizen of Old Europe
Odysseus
 
Posts: 205
Joined: Wed Sep 10, 2003 9:34 pm
Location: Belgium

Postby pbakker » Thu Apr 08, 2004 9:21 am

Maybe this can help: I have a situation where an Onrecordselection method is triggered, while i do not want it.

What I've done is create a global called "proccontrol". If I start a method that will trigger the OnRecordSelection method while I do not want to, I set this global to, for example 1 at the beginnong of the method.

In the OnRecordSelection method I put an if...else clause, evanuating the global. If the global is 1, the OnRecordSelection method jump right to the end, basically not doing anything.

Offcourse, at the end of your method that you don't want to trigger the OnRecordSelect method, you have to set the global back to 0, or else the OnRecordSelection method never does anything anymore.

It will take some time to get this to work properly, especially in complex method structures, but it works..

Hope this will help you forward.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Postby Odysseus » Thu Apr 08, 2004 10:17 am

Thanks Paul

but :?

it seems onRecordSave cannot be overriden.
So if I understand this correctly this means that whatever code I attach to the event the built in behaviour is executed (Servoy tries to save the record to the DB) :cry:

So maybe I should look at ways of preventing the event from being fired.
It is now fired when you click outside a field on the form (just clicking on the background)

Any ideas ?
Odysseus

Citizen of Old Europe
Odysseus
 
Posts: 205
Joined: Wed Sep 10, 2003 9:34 pm
Location: Belgium

Postby Jan Blok » Wed Jul 07, 2004 10:34 pm

Servoy 2.1 beta 3 and 4 has:
Code: Select all
application.setFocusLostSaveEnabled(true/false)

which enables you to fill all columns required and do a manual:
Code: Select all
controller.saveData()

to trigger a database insert or update
Jan Blok
Servoy
Jan Blok
 
Posts: 2684
Joined: Mon Jun 23, 2003 11:15 am
Location: Amsterdam


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 35 guests

cron