We have a query that is pulling from a retool database. When we run the query we get 198 results, in side of thee results we have address and branches. I need to filter this query down to only show the unique branches.
I have built a javascript that filters down the results the way I want them but I can not get this returned to a retool table.
Here is the javascript I have built:
Query_Branches.trigger({
// You can use the argument to get the data with the onSuccess function
onSuccess: function (data) {
//console.log("Successfully ran!");
// Output the structure of the data to the console for inspection
//console.log(data);
const filteredLocations = data.id.map((id, index) => ({
id,
name: data.name[index],
city: data.city[index],
state: data.state[index],
address: data.address[index],
suite: data.suite[index],
customer_id: data.customer_id[index],
latitude: data.latitude[index],
longitude: data.longitude[index],
zipcode: data.zipcode[index],
branch_number: data.branch_number[index],
location_id: data.location_id[index],
master_branch: data.master_branch[index],
}));
//console.log(filteredLocations);
const uniqueAddresses = [];
const uniqueFilteredLocations = [];
filteredLocations.forEach(location => {
if (!uniqueAddresses.includes(location.address)) {
uniqueAddresses.push(location.address);
uniqueFilteredLocations.push(location);
}
});
console.log(uniqueFilteredLocations);
return uniqueFilteredLocations;
},
});
Console log shows the data inside of uniqueFilteredLocations but I can not return this. I do not get a Output when I run the query.
What am I missing and how can I get this to show an output?