Page 1 of 1

A Newbie question - forward and back

PostPosted: Sun Jul 03, 2011 12:54 pm
by itgenetics
Hi guys - apologies for this daft question. I have been busy creating a database and am now onto the forms. I can create a new record, but I cannot get the forward and back methods to work. I have found the methods under history. I have created a form method called forward and another called back. When I test it under web client, the little red "loading" message shows but the record does not move on. Have I missed something or am I being dense? Thanks in advance.

Re: A Newbie question - forward and back

PostPosted: Sun Jul 03, 2011 1:17 pm
by jasantana
Hi the methods you have found under the history root is about the forms shown, not about records.

If you want to move thru the records programatically you have to use code like this:

Code: Select all
foundset.setSelectedIndex(foundset.getSelectedIndex()+1)   // goes forward
foundset.setSelectedIndex(foundset.getSelectedIndex()-1)   // goes backward


i hope this helps.

Re: A Newbie question - forward and back

PostPosted: Sun Jul 03, 2011 1:21 pm
by itgenetics
This is perfect. It works!

Re: A Newbie question - forward and back

PostPosted: Sun Jul 03, 2011 1:22 pm
by itgenetics
I guess that these should be global methods? As I will use them throughout my solution.

Re: A Newbie question - forward and back

PostPosted: Sun Jul 03, 2011 1:46 pm
by jasantana
itgenetics wrote:I guess that these should be global methods? As I will use them throughout my solution.


Can be a form method or global method. That is up to you, but in the case you be using a global method instead of form method you must take into account that the global method will not know the foundset.

What I use to do is:
1. Create a form that holds all the basic code for a table maintenance form.
2. When creating the maintenance form that I want I extend the, let´s say, class form.
3. I normally don´t use foundset.getSelectedIndex...... bla bla bla what I do is something like:

Code: Select all
/**
* Va a Primer Registro
*
* @param {JSEvent} event the event that triggered the action

* @properties={typeid:24,uuid:"08DC7FAE-6125-41C7-8DEA-C7A862E4E657"}
*/
function goFirstRecord(event) {
   var frm = currentcontroller.getName();
   if(forms[frm].frmIsEditing){
      // If the form is editing a record we ask what to do
      globals.askForSaving(frm);
   }
   if(!forms[frm].frmIsEditing){
      var _foundset=forms[frm].foundset
      _foundset.loadAllRecords();
      _foundset.setSelectedIndex(1)
   }else{
      forms[frm].controller.focusFirstField();
   }
}

/**
* Va al Registro Anterior
*
* @param {JSEvent} event the event that triggered the action

* @properties={typeid:24,uuid:"F5EA831C-3923-4A49-8223-19EDA5D5D560"}
*/
function goPreviousRecord(event) {
   var frm = currentcontroller.getName();
   if(forms[frm].frmIsEditing){
      // If the form is editing a record we ask what to do
      globals.askForSaving(frm);
   }
   if(!forms[frm].frmIsEditing){
      var _foundset=forms[frm].foundset
      _foundset.loadAllRecords();
      _foundset.setSelectedIndex(_foundset.getSelectedIndex()-1);
   }else{
      forms[frm].controller.focusFirstField();
   }
}

/**
* Va al Registro Siguiente
*
* @param {JSEvent} event the event that triggered the action

* @properties={typeid:24,uuid:"E389D3C1-5D05-427C-A96A-4E13398EA8FF"}
*/
function goNextRecord(event) {
   var frm = currentcontroller.getName();
   if(forms[frm].frmIsEditing){
      // If the form is editing a record we ask what to do
      globals.askForSaving(frm);
   }
   if(!forms[frm].frmIsEditing){
      var _foundset=forms[frm].foundset
      _foundset.loadAllRecords();
      _foundset.setSelectedIndex(_foundset.getSelectedIndex()+1);
   }else{
      forms[frm].controller.focusFirstField();
   }
}

/**
* Va al ultimo Registro
*
* @param {JSEvent} event the event that triggered the action
*
* @properties={typeid:24,uuid:"27932FFB-422E-4F3F-AB56-6EC636BEFD3E"}
*/
function goLastRecord(event) {
   var frm = currentcontroller.getName();
   if(forms[frm].frmIsEditing){
      // If the form is editing a record we ask what to do
      globals.askForSaving(frm);
   }
   if(!forms[frm].frmIsEditing){
      var _foundset=forms[frm].foundset
      _foundset.loadAllRecords();
      _foundset.setSelectedIndex(databaseManager.getTableCount(_foundset));
   }else{
      forms[frm].controller.focusFirstField();
   }
}


This works for me, even though any Servoy Guru might give US a better way do get this done.

Re: A Newbie question - forward and back

PostPosted: Sun Jul 03, 2011 5:28 pm
by ROCLASI
The event argument already holds the form name it was triggered from.
Also the currentcontroller will be the controller of the topmost form, so if you are calling it from any forms in tabpanels on this form then you won't get the expected result.
So your code can be changed like so:
Code: Select all
function goFirstRecord(event) {
   var frm = event.getFormName();
//etc..


Hope this helps.

Re: A Newbie question - forward and back

PostPosted: Sun Jul 03, 2011 6:07 pm
by jasantana
Hi Robert.

The form is not working inside a TabPanel, that is the reason it works for me, but I will cchange my code for future purposes.

Thanks.

Re: A Newbie question - forward and back

PostPosted: Mon Jul 04, 2011 8:07 pm
by itgenetics
Thanks guys - ideal!