//for ALL customers//shows all the invoices of all customers in the current foundset
var allInvoices = forms.invoices.controller.showRecords(databaseManager.convertFoundSet(foundset, customers_to_invoices));
I want to do the opposite, on a many to one relation.
I have a foundset of invoices and I want to show all companies in my Companies form.
//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.concat(myArray[i])
lastValue = myArray[i]
}
}
forms.customers.controller.showRecords(ids)
//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]
}
}
//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)
You’re welcome! One important note: the controller.show() and controller.loadRecords() will only work with a maximum of 200 unique ids. This is due to the fact that many sql databases will only allow 200 items in an “in” query.
Just to be “safe” you might want to enhance the code to read:
//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')
}