A Newbie question - forward and back

Questions, tips and tricks and techniques for scripting in Servoy

A Newbie question - forward and back

Postby itgenetics » Sun Jul 03, 2011 12:54 pm

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.
itgenetics
 
Posts: 63
Joined: Fri Apr 08, 2011 11:26 am
Location: Cambridge, UK

Re: A Newbie question - forward and back

Postby jasantana » Sun Jul 03, 2011 1:17 pm

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.
Best regards,
Juan Antonio Santana Medina
jasantana@nephos-solutions.co.uk
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 555
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: A Newbie question - forward and back

Postby itgenetics » Sun Jul 03, 2011 1:21 pm

This is perfect. It works!
Last edited by itgenetics on Sun Jul 03, 2011 1:42 pm, edited 1 time in total.
itgenetics
 
Posts: 63
Joined: Fri Apr 08, 2011 11:26 am
Location: Cambridge, UK

Re: A Newbie question - forward and back

Postby itgenetics » Sun Jul 03, 2011 1:22 pm

I guess that these should be global methods? As I will use them throughout my solution.
itgenetics
 
Posts: 63
Joined: Fri Apr 08, 2011 11:26 am
Location: Cambridge, UK

Re: A Newbie question - forward and back

Postby jasantana » Sun Jul 03, 2011 1:46 pm

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.
Best regards,
Juan Antonio Santana Medina
jasantana@nephos-solutions.co.uk
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 555
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: A Newbie question - forward and back

Postby ROCLASI » Sun Jul 03, 2011 5:28 pm

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: A Newbie question - forward and back

Postby jasantana » Sun Jul 03, 2011 6:07 pm

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.
Best regards,
Juan Antonio Santana Medina
jasantana@nephos-solutions.co.uk
Servoy MVP 2015
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 555
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: A Newbie question - forward and back

Postby itgenetics » Mon Jul 04, 2011 8:07 pm

Thanks guys - ideal!
itgenetics
 
Posts: 63
Joined: Fri Apr 08, 2011 11:26 am
Location: Cambridge, UK


Return to Methods

Who is online

Users browsing this forum: No registered users and 10 guests