To re-create this for yourself - create a new solution with two forms (both based on the "example_data" connection): customers, orders. You can put a few fields on each - just be sure to include the customerid field (so you can search by it).
Go to the orders form and find "FRANK" and "VINET" in the customerid field. You should have 20 records.
Create a method on the orders form called "goToRelatedCustomers":
- Code: Select all
//Returns a foundset dataprovider (normally a column) as JavaScript array
var myArray = databaseManager.getFoundSetDataProviderAsArray(foundset,'customerid').sort();
var ids = new Array()
var lastValue = ''
//loop through the array to get the unique customer id
for ( var i = 0 ; i < myArray.length ; i++ )
{
if(myArray[i] != lastValue)
{
ids.unshift(myArray[i])
lastValue = myArray[i]
}
}
if(ids.length <= 200)
{
//Converts the argument to a JSDataSet with one column that can be used in controller.loadRecords(pkdataset)
var temp = databaseManager.convertToDataSet(ids)
forms.customers.controller.showRecords(temp)
}
else
{
plugins.dialogs.showErrorDialog('Error!', 'Too many unique customers found: ' + ids.length + '\n200 maximum allowed.', 'OK')
}
I hope this helps in your development efforts!
This code works in Servoy 2.1 and higher