Go To Related: Many To One

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

Go To Related: Many To One

Postby bcusick » Fri Mar 18, 2005 2:37 pm

I was working with the "example_data" connection the other day, and I had a foundset with 20 orders in it - and I wanted to show all the customers that had an invoice in the foundset.

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
Bob Cusick
bcusick
 
Posts: 1255
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Return to How To

Who is online

Users browsing this forum: No registered users and 12 guests