Automating Servoy default controller to scroll down automati

Hi all,

In one of the Servoy forms Im using default controller and View the form as Record View.
Some times after doing search we find more the one record.
If there is more then one record was fund, is there a way to make Servoy Controller to scroll down automatically and viewing each record for second.

Please let me know.

Thanks in advance,

Abrahim

Abrahim,

This following code will scroll through each record. However, you will not be able to stop until the last record. Very bad if your search finds more than a few records. I’ve included 3 options below.

if (controller.getMaxRecordIndex() > 1)
{
	for (var i = 1; i <= controller.getMaxRecordIndex(); i++)
	{
		controller.recordIndex = i;
		//Sleep for 1/2 second
		application.sleep(500);
	}
}

OPTION 1
Show a list view where the user can select the record to view.

if (controller.getMaxRecordIndex() > 1)
{
	forms.listView.controller.show()
}

OPTION 2
Same as above except the form is shown in a dialog.

if (controller.getMaxRecordIndex() > 1)
{
	application.showFormInDialog(forms.listView,100,80,500,300,'my own dialog title',false,true,true);
}

OPTION 3
Show a dialog when more than 1 record is found.

if (controller.getMaxRecordIndex() > 1)
{
	plugins.dialogs.showInfoDialog('Multiple Records Found', 'Your search found '+ controller.getMaxRecordIndex() +' records.', 'OK')
}

I prefer option 1 or 2. Hope this helps!

Another option:

if (controller.getMaxRecordIndex() > 1) 
{ 
	plugins.dialogs.showInfoDialog('Multiple Records Found', 'Your search found '+ controller.getMaxRecordIndex() +' records. Switching to list view.', 'OK') 
	forms.listView.controller.show()
}

Greg,

I tried the following code:

if (controller.getMaxRecordIndex() > 1)
{
for (var i = 1; i <= controller.getMaxRecordIndex(); i++)
{
controller.recordIndex = i;
//Sleep for 1/2 second
application.sleep(500);
}
}

And it does exactly what I was looking for!!!

The other options are useful too.

Thanks,

Abrahim

I’m glad I could help. I noticed something you might want to change.

replace:
controller.recordIndex = i;

with:
controller.setSelectedIndex(i);

It does the same thing but setSelectedIndex is the new/correct way.

Thanks Greg,

I updated the code and here is what Ill be using:

if (controller.getMaxRecordIndex() > 1)
{
plugins.dialogs.showInfoDialog(‘Multiple Records Found’, ‘Your search found ‘+ controller.getMaxRecordIndex() +’ records.’, ‘OK’)
for (var i = 1; i <= controller.getMaxRecordIndex(); i++)
{
controller.setSelectedIndex(i);
//Sleep for 1/2 second
application.sleep(500);
}
}

It works like a charm!

Could you please explain the following code in simple English?

for (var i = 1; i <= controller.getMaxRecordIndex(); i++)

Thanks,

Abrahim

Could you please explain the following code in simple English?

for (var i = 1; i <= controller.getMaxRecordIndex(); i++)

Abrahim,

With a little help from the Servoy Advanced Programming Guide and Build Your Own Database Driven Website by sitepoint.com, here’s the skinny.

Syntax:
for (initialization; test condition; iteration statement)

Explanation:
The intialization statement is executed once (and only once) at the start of the loop. The test condition is checked each time through the loop, before the body statements are executed. The iteration statement is executed each time through the loop but after the body statements are executed.

Servoy Advanced Programming Guide
http://developer.servoy.com/docs/ServoyAdvProgGuideFMP.pdf

Thanks Greg,

Abrahim