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.
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')
}
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()
}
if (controller.getMaxRecordIndex() > 1)
{
for (var i = 1; i <= controller.getMaxRecordIndex(); i++)
{
controller.recordIndex = i;
//Sleep for 1/2 second
application.sleep(500);
}
}
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++)
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.