I have a donations report that returns records where the contact is not unique (as in, one or often more donations per contact, each in a separate row). I’d like to use that found set (in the donations table) to then set the found set of the contact table.
Using getFoundSetDataProviderAsArray(forms.report, ‘fk_contact’), fk_contact may not be unique and the array will contain duplicate values. How can I constrain it so that only unique values are in the array?
If you can you select the foundset via a distinct on that field. But that would give you a different foundset than you have now.
If that is not an option you need to do it yourself. Like this:
var aContact = databaseManager.getFoundSetDataProviderAsArray(forms.report, 'fk_contact'),
nCurID = null,
aUniqueContact = new Array();
aContact.sort();
for ( var i = 0 ; i < aContact.length ; i++ )
{
if ( aContact[i] != nCurID )
{
aUniqueContact.push(aContact[i]);
nCurID = aContact[i];
}
}
// aUniqueContact will have the unique FK's
Not sure that this will work with duplicate keys in the array so an untested answer is to convert the array to a dataset and then load the records using that dataset.
Assuming that the original array is called ‘donation’ then you could have:
//Returns a foundset dataprovider (normally a column) as JavaScript array
var donation = databaseManager.getFoundSetDataProviderAsArray(forms.report,'fk_contact');
//converts an array to a dataset
var dataset = databaseManager.convertToDataSet(donation);
//load records using the dataset
forms.contact.controller.loadRecords(dataset)
That was my experience, as well (duplicate records). I was hoping that there was an argument of the function that would constrain to unique values. I’m pretty sure there such a thing in getDataSetByQuery, but perhaps not in getFoundSetDataProviderAsArray.
Is it possible to have a an argument for getFoundSetDataProviderAsArray for “unique value”? Worth a feature request?
Jim
p.s. Robert, your approach looks like a good solution! Thanks also to Harry!
var aContact = databaseManager.getFoundSetDataProviderAsArray(forms.search.foundset,‘fk_contact’);
nCurID = null,
aUniqueContact = new Array();
aContact.sort();
for ( var i = 0 ; i < aContact.length ; i++ )
{
if ( aContact != nCurID )
{*
_ aUniqueContact.push(aContact*);_ _ nCurID = aContact; } }* var dataSet = databaseManager.convertToDataSet(aUniqueContact) forms.contact.controller.loadRecords(dataSet)[/quote] and it works as expected._