I am having trouble using the onRecorEditStart.
This is what I am trying to do:
- When a user starts editing a record, I lock the record.
- When another user tries to edit the record, I know it. So I show a message (a dialog) to show this user that someone else is locking the record.
- After that message, I try to set the focus to another field.
My problem is:
- Even if I set the focus to another field, the record stays on edit mode (e on Servoy’s form). So the user can click again on it and I won’t be able to show the message again to prevent the user from typing on the field.
- As the user might keep typing on the field, he will write down data that will not be recorded.
What am I doing wrong?
How should I manage this concurrency problem?
what should step <3> exactly do in your eyes then?
Do you want to stop the record from editing? call saveData()
I don’t really see anything.
The focus goes away from the field but I can still “re-select” the field. As the edit mode keeps on Servoy, I don’t get a new message…
Maybe if I show you my code, this might help a bit…
function onRecordEditStart(event) {
//get the formName
var frm_name = event.getFormName();
//get the tablename
var jsTabla = databaseManager.getTable(forms[frm_name].foundset)
var tabla = jsTabla.getSQLName()
if (forms[frm_name].foundset != null) {
var RowIdentifierColumnNames = jsTabla.getRowIdentifierColumnNames();
var idBloqueo = forms[frm_name][RowIdentifierColumnNames[0]] + ‘’;
idBloqueo = idBloqueo.length + ‘.’ + idBloqueo + ‘;’
if (!databaseManager.acquireLock(forms[frm_name].foundset, 0, idBloqueo + ‘’ + idBloqueo)) {
databaseManager.saveData()
forms.nav_frm_principal.elements.fld_registroActual.requestFocus(false);
databaseManager.saveData()
forms.nav_frm_principal.elements.fld_registroActual.requestFocus(false);
//I check who has the lock. Custom made…
var query = ‘SELECT usuario_vc FROM TB_BLOQUEOS where tabla_vc = ? and pk_vc = ? order by ID_bloqueo desc’;
var args = new Array();
args[0] = tabla
args[1] = idBloqueo
var dataset = databaseManager.getDataSetByQuery(‘ivi_gc’, query, args, 1);
if (dataset == null || dataset.getMaxRowIndex() == 0) {
plugins.dialogs.showErrorDialog(“Error”, “Record in use”, i18n.getI18NMessage(‘ivi.gc.msg.aceptar’));
} else {
plugins.dialogs.showErrorDialog(“Error”, “Record in use” + dataset.getValue(1, 1), i18n.getI18NMessage(‘ivi.gc.msg.aceptar’));
}
return -1;
}
}
return;
}
so you want to go out of edit directly when you can’t get a lock?
try to just “return false” when the edit shouldn’t happen.
Thanks a lot. That worked.
Now I am facing a different kind of trouble.
My form is based on a table; it has a tabPanel based on another table and; and finally, a third form (a tabPanel on the second form) based on a third table.
What I want to lock is just the record I am editing.
(that is, if I am typing on a field based on the third form/table, that should be the only record on edition).
Is there a way to do this?
I think that Servoy’s behaviour is to lock all records (the record based on the first table and all the related tables/records due to the tabPanels)
Thanks a lot,
Miguel.-
it is not servoy’s behavior to lock all the records, locking is purely based on the record you give to it. That record is locked.
Right, Johan.
I am sorry, I didn’t make myself understand…
If we have a form based on a table, I can lock just one record. Great.
That is the code shown in previous posts. It is now working fine.
But on my form I can have fields based on my own table and fields based on a relation to another table.
Let’s say that my form is based on a table A and the field I am editing is based on a table B; the field is shown on my form through a relation A_to_B
In this case…
- Is there a way to be able to find out that I am really editing a field based on table B through a relation?
- Can I just lock this record from table B, instead of locking my selected record on table A?
Thanks in advance, Johan.
if you know what is on your screen, why are you not just locking all the records (so the main and related) if you do want to lock that?
I want to be as clean as possible.
Our system is used in a clinic where many biologists access the same information at the same time, and I would like to cause the least possible trouble.
So if a user is just using a record, I would like to lock just that one record.
Should I reverse the way I am locking records?
Should I lock a record every time a field is edited, in order to lock just what the user is really editing/modifying?
An example:
---->
Let’s mix my previous sample with the code we are using…
F1. Form 1 based on table A
FLD1. Field on form F1 based on table A
FLD2. Field on form F1 based on table B. It is linked on the form throgh a relation A_to_B
---->
function onRecordEditStart(event) {
var frm_name = event.getFormName();
var jsTabla = databaseManager.getTable(forms[frm_name].foundset)
var tabla = jsTabla.getSQLName()
[…]
databaseManager.acquireLock(forms[frm_name].foundset, 0, ‘lock’)
[…]
<----
If we start editing FLD2, with the previous code we are really locking the selected record on table A.
BUT NOT THE SELECTED RECORD ON TABLE B, THE ONE WE REALLY CARE ABOUT.
Because this is our real trouble: to prevent two users from editing the same record on table B.