A Newbie question - forward and back

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.

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:

foundset.setSelectedIndex(foundset.getSelectedIndex()+1)   // goes forward
foundset.setSelectedIndex(foundset.getSelectedIndex()-1)   // goes backward

i hope this helps.

This is perfect. It works!

I guess that these should be global methods? As I will use them throughout my solution.

itgenetics:
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:
/**
 * 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.

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:

function goFirstRecord(event) {
   var frm = event.getFormName();
//etc..

Hope this helps.

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.

Thanks guys - ideal!