Hi Paul, Andrei
Thanks, I added the return values.
The behaviour of this event is still very strange, we don’t get usable results. The problems so far found (autosave = on):
-
The onRecordInsert event is executed 5 times - why??? With this behaviour, it is not possible to put plugins.dialogs.xxx in this event as it is executed 5 times
-
If one inserts a record and uses a databaseManager.rollbackEditedRecords(), the selected record is always 1 off, as the onRecordSelection event is executed BEFORE the onRecordInsert event.
-
If there is an error and onRecordInsert is fired, the onRecordSelection event is always executed twice and shows once the index of the (newly) added record (which is still not saved as it has an error) and once the index of the clicked record (which triggers the onRecordInsert event, i. e. tries to autosave the record)
-
We think the solution could be if the onRecordInsert is fired after the onRecordSelection event, as we then would know the correct record index (we are though not exactly aware of all other possible implications)
-
The cmd forms[currentFormName].elements.fldCode.requestFocus() does not work
Conclusion: At the moment we can’t get the onRecordInsert to work as (we think) it is intended (without a lot of workaround programming).
And as it is called every time 5 times, we can’t put a dialog to inform the user about an error in it as it is executed 5 times anyway.
At the moment, we are stuck and don’t know exactly how to continue, good it’s weekend .-)
Best regards, Robert
Code of onActionAddRecord, i. e. button add record:
/*
Title: Create a new subject
Author: Robert Huber
Created: 16.08.2007
Modified: -
Arguments: -
Returns: -
Notes: -
*/
controller.newRecord();
setReadOnly(false);
Code of onRecordInsert:
/*
Title: Validate mandatory columns
Author: Robert Huber, Birgit Rieder
Created: 17.08.2007
Modified: -
Arguments: arguments[0] is record being processed
Returns: -
Notes: -
*/
var record = arguments[0];
var currentFormName = application.getMethodTriggerFormName();
if (record.code == null || record.code == “” || record.name == null || record.name == “”)
{
var dialogResult = plugins.dialogs.showErrorDialog( “Error”, “Code und Fach verlangen eine Eingabe”, ‘Abbrechen’, ‘Bearbeiten’);
if (dialogResult == “Abbrechen”)
{
forms[currentFormName].controller.readOnly = true;
databaseManager.rollbackEditedRecords();
// workaround to decrease the record index by one after the onRecordSelection event
// add a job that runs at the given date (20 seconds in the future)
// and repeats that every 20 seconds for 40 times or the enddate is reached (0 for no repeats = just one call)
var startDate = new Date();
startDate.setTime(startDate.getTime()+100);
var endDate = new Date(startDate.getTime()+100000);
plugins.scheduler.addJob(‘in2seconds’,startDate,setIndexMinusOne,20000,0,endDate)
}
// needs work (does not yet work):
// if (currentFormName != null)
// {
// forms[currentFormName].elements.fldCode.requestFocus();
// }
return false;
}
else
{
forms[currentFormName].controller.readOnly = true;
return true;
}
Code of onRecordSelection:
/*
Title: A new record is selected. If the form is in edit mode and the selected
record is not the edited record, reselect the edited record and do not
allow to select another record.
Author: Robert Huber, Birgit Rieder
Created: 17.08.2007
Modified: -
Arguments: -
Returns: -
Notes: -
*/
//application.output("selected index: " + forms.ScoSubjectsL.controller.getSelectedIndex());
//application.output("selected code: " + code);
if (isReadOnly() == false)
{
var selectedIndex = controller.getSelectedIndex();
if (selectedIndex != editIndex)
{
controller.setSelectedIndex(editIndex);
}
}
pbakker:
Robert, you’re not returning true or false, like in the sample code I provided you with in the other thread. If you do not return false, the insert is not canceled!!!
Paul