Errormessage from controller.deleteRecord

Hi,

In my script I have some coding:

var _form = “xxx” (formname, not imporant)
var _returnValue

_returnValue = forms[_form].controller.deleteRecord();

the _returnValue variable returns the value false.
which probably means that the delete was not succesfull.
But there is in my opinion no reason why this record should not be deleted.
I checked all my relations and all seem to be OK.

Is there anyway in Servoy where I can get the error why the delete didn’t succeed. I tried databaseManager.getLastDatabaseMessage(), but this returns an empty value.

How can I show the message, why the delete could not be done.
If I know how to show this message, I can find out what is exactly wrong in my database.

I’m working with 3.5RC5 and SQL Server 2005 as database

Thanks for your reply

Martin

deleteRecord is void, so it should not return anything. Are you sure the record is not deleted (that should be easy to figure out)?

Hi Martin,

If you are on v3.x then you have a new node in the method editor tree called : ServoyException

The functions in here are geared around catching errors and returning details

In the meantime, have you debugged the method by changing the ‘_form’ variable to the actual form name within the delete command to ensure that it works (or does not !) with the form variable out of the method - or running without without trying to return the delete result into the variable ?

Cheers
Harry

patrick:
deleteRecord is void, so it should not return anything. Are you sure the record is not deleted (that should be easy to figure out)?

DeleteRecord is boolean and if delete succeeds it returns true otherwise false. See syntax in Servoy statusbar
Perhaps in 3.1 it was void.
It tested it and it gives true/false corresponding to if record was delete or not

OK. I have 3.1 and there it’s void. Then you can use Harry’s approach. Anyway, whenever deletion fails, you should get an error (have you checked the console/log?).

Harry Catharell:
If you are on v3.x then you have a new node in the method editor tree called : ServoyException

Thanks for the hint.
I didn’t know this.
I’ll check it out immediately

Thanks

Martin

I tried the exception object, but no result:

databaseManager.getLastDatabaseMessage = spaces
ServoyException.getMessage = ‘Unknown errorcode’
ServoyException.getErrorCode = 0
ServoyException.getSQLState = org.mozilla.javascript.Undefined@d2e2a4
ServoyException.getVendorErrorCode = org.mozilla.javascript.Undefined@d2e2a4

So no errorcode or errormessage.

Could this perhaps be a bug?

Couple of questions first:
the code “forms[_form].controller.deleteRecord();” returns false.

1: Is there actually a record to delete? What shows if you do ```
application.output(PK) //Replace PK with the name of the column that is the PK


2: Lets assume there is a record to delete: When you delete the record, I assume you have autosave off, so nothing is send to the database yet, so retrieving the Database error message is not meaningfull. 

Can you check the admin pages for any errors in the log?

Also, might there be something preventing the delete? security settings maybe? An onRecordDelete event on the table that is returning false?

Paul

The correct key appears in the output section. So that is not the problem.

Autosave is off
There are no errormessages in logfile concerning this delete

Isn’t there anyway that I can get an errormessage why the delete didn’t succeed? I always want to show or log an errormessage, not only in this case.
Even when some relationsetting stops the record from deleting this record, I need to know what relation stopped the delete.

There are no security settings (all Implicit) or onRecordDelete event on that table. and also on the form both viewable and accesible

Even when some relationsetting stops the record from deleting this record, I need to know what relation stopped the delete.

Are you saying you’re trying to delete over a relation?

Anyway, first we need to figure out why it fails. The questions I asked are to determine that. For example, if there was an onRecordDelete method on the table preventing the delete, you would be in charge of presenting a message or any kind of feedback to the user. But, as you responded: there is no onRecordDelete event attached, so we can rule that out.

So, to recap:

  • There is a record
  • You try to delete the record on the controller itself, so not over a relation
  • There are no Security settings preventing deletion of records from that table
  • There is no onRecordDelete event attached to the table that returns false
  • there are no errors in the log

Next two questions:

  • From the table that you try to delete from: Are there relations defined to other tables where the AllowParentDeleteWhenHavingRelatedRecords flag is set to false?
  • You posted the following:

ServoyException.getMessage = ‘Unknown errorcode’
ServoyException.getErrorCode = 0
ServoyException.getSQLState = org.mozilla.javascript.Undefined@d2e2a4
ServoyException.getVendorErrorCode = org.mozilla.javascript.Undefined@d2e2a4

Where did you get that from? Was the onErrorMethod triggered, but with a strange errorCode, or…?

Paul

OK, I found the solution.

I thought that ‘Allow parent delete when having related records’ and ‘Delete related records’ were mutual exclusive, but it doesn’t work like this.

I’ve seen that you have to put both options ON when you want to delete the childrecords.

But still remains my request how I can get an errormessage that the delete was not allowed. I need some way to find out why a delete could not be done, which relation stopped it.

The coding about ServoyException.getMessage I tried to see if there were any messages. You spoke about the onError method. Where can I find this method? I didn’t find it in the Referenceguide neither in the Usersguide.

On solution level, you can set an onErrorMethod for the solution. Any errors raised, will then be ported through this method.

You can set the method under “solution settings”. For samplecode, see the samplecode of “isServoyException” under the ServoyException node.

This functionality isn’t well documented, but this will be corrected in the 3.5 docs.

There does seems to be an issue when a delete is blocked due to the " Allow parentdelete when having related record" option being disabled. No error is raised in that case. will be looked at.

Paul

This situation is still actual. When a deleteRecord() fails, there is still no trace about the error.

The databaseManager.getFailedRecords() doesn’t return any failed records.

Also the databaseManager.lastDatabaseMessage() is empty

Can this still be fixed in 3.5.7?
I’ll check if I made a call last year.

I agree with Martin !

Error handling changes
In Servoy 4.0, the error handling of record deletion was slightly changed:
In Servoy 3.5, when deletion of records fails because of servoy-application-checks, an error message is logged, the delete is rejected and scripting methods return value false.
In Servoy 4.0, when deletion of records fails because of servoy-application-checks, a ServoyException is thrown. When an on-error method is defined, the exception will be passed to the method.

New Exception error codes
As a consequence of the error handling change described above, two new ServoyException error codes have been defined:

error 331: NO_PARENT_DELETE_WITH_RELATED_RECORDS :
i18nmessage: servoy.foundset.error.noParentDeleteWithRelatedrecords

error 332: DELETE_NOT_GRANTED :
i18nmessage: servoy.foundset.error.deleteNotGranted

Paul