Detect new record within onShow?

If a record has just been created using,

forms.asmt_aux1_base_form.controller.newRecord(false);

…and then I display it as a tab on another form,

forms.asmt_right_panel.elements.tabs_320.tabIndex = tabNumber;

…then is there a “new record” event which I can use in the onShow event on that tab (form), to perform other operations? Or do I need to maintain my own global variable?

Thank you,
Don

Maybe you could use databasemanager.hasnewrecords or geteditedrecords ?

Hello Hans,

I tried a trace. Right after I issue the command,

forms.asmt_aux1_base_form.controller.newRecord(false);

…when I try entering in the interactive console the following

databaseManager.hasNewRecords(forms.asmt_aux1_base_form.foundset, forms.asmt_aux1_base_form.foundset.getSelectedIndex())

I get “true”. However, when I try the same thing in the onShow event of the form (in the tab), it is “false”. Even though I haven’t performed any edits yet.

Is this how it should be working? Is there a workaround or should I proceed with my original idea?

Thank you,
Don

Do You have autosave on ?
If you do then leaving the record will do a save and there will be no new records in the tabbed form.
Or else can you upload a small sample to look at ?

Hello Hans,

Yes, I have left autosave on. So even though I haven’t clicked into a field (the record is created in a non-displayed form), it is already past the “new record” status when the display form comes up?

The existing application (not Servoy) saves when the user clicks (navigates) from page to page on the web. Because there are hundreds of users and they want simultaneous access to the same records, I thought that autosave would be the safest approach in Servoy – as soon as a user moves out of a field, their work gets saved.

Thank you,
Don

Well, I am not sure about that, but I guess that when the focus moves to the form that is shown, an autosave is done.

Maybe one of the Servoyans can answer this one ?

Hi again Hans,

I’m also experiencing some difficulties with cancelling the form in dialog. Initially, the user presses a “+” button on the data entry form to create the included record,

function newRecord_calendar(event) {
forms.calendar_incl.controller.newRecord(false);
forms.calendar_incl.cldr_description = “New calendar item”;
forms.calendar_incl.cldr_start_d = new Date();
forms.calendar_incl.cldr_foreign_key = forms.district_i.dist_district_id;
globals.newDDrecord_B = true;
application.showFormInDialog(forms.calendar_i, -1,-1,-1,-1, ‘New calendar item’, false, false, ‘calendar_i’, true);
}

Then if the user presses the Cancel button on the form in dialog,

function btn_cancel(event) {
var rec = foundset.getRecord(foundset.getSelectedIndex());
if (globals.newDDrecord_B == true) {
controller.deleteRecord();
} else {
rec.rollbackChanges();
}
application.closeForm();
}

What I’m finding is that after the dialog closes, the new record is still listed in calendar_incl, despite having been deleted with the cancel button in the dialog.

Am I approaching this the wrong way?

Thank you,
Don

I think that I found the problem with the last posting. It’s a shared table (calendar information) that links to other tables/records with the same foreign key field. I was using defined relations in the tab panel rather than running a procedural search in onShow. I was also using the same table/list form for the tab panel display on different data entry forms. This apparently was causing Servoy to display the wrong records (as well as other odd symptoms).

I switched to using separate table/list forms for the calendar in the different data entry forms, and a procedural search in onShow. That seems to have resolved it.

Thanks,
Don

Ok, nice.

I looked at your first question where you say :

I tried a trace. Right after I issue the command,

forms.asmt_aux1_base_form.controller.newRecord(false);

…when I try entering in the interactive console the following

databaseManager.hasNewRecords(forms.asmt_aux1_base_form.foundset, forms.asmt_aux1_base_form.foundset.getSelectedIndex())

I get “true”. However, when I try the same thing in the onShow event of the form (in the tab), it is “false”. Even though I haven’t performed any edits yet.

Is this how it should be working? Is there a workaround or should I proceed with my original idea?

Thank you,
Don

You use : databaseManager.hasNewRecords(forms.asmt_aux1_base_form.foundset, forms.asmt_aux1_base_form.foundset.getSelectedIndex())

maybe in the tab the new record is not the currently selected one ?

You could try “databaseManager.hasNewRecords(forms.asmt_aux1_base_form.foundset, forms.asmt_aux1_base_form.foundset”

It is hard to give more advise.
If you need more advise, maybe you can upload a small sample solution ??

Regards,

Hi Hans,

I think you may be correct regarding the autosave state. I tried turning it off just before creating the new record, and then tracing the code in the onShow method. (I also used the longer syntax you suggested for hasNewRecords().)

This time it does recognize the new record and steps through that section of the code. However, I do get three console complaints,

“Couldn’t do a sort because there where edited records on this foundset”

Thank you,
Don