I had someone else write this code so that users can download data of one organization directly from the wix collection. They choose their organization name in the drop down menu, then click the download button which gives them an excel sheet of all the data from that organization. This was working months ago when it was first implemented but for some reason is only exporting the first 9 columns now (org name, email, first name, address, phone, id, owner, created date, and updated date) but none of the columns with the actual data which is another 22 columns.
Can someone look at my code and tell me if they see any indicators of why this might be happening?
import wixData from ‘wix-data’ ;
let dataToUpload = null ; // We will add our data collection to this buffer
$w.onReady( function () {
populateDropdown( “FoodBank” );
populateDropdown( “FreshProduce” );
populateDropdown( “MealProgram” );
});
function populateDropdown(table) {
return wixData.query(table)
.ascending( ‘organization’ )
.distinct( “organization” )
.then( (results) => {
var dropdownOptions = ;
results.items.forEach(org => dropdownOptions.push({ “label” : org, “value” : org}));
$w( ‘#orgDropdown’ +table).options = dropdownOptions;
} )
// something went wrong
. catch ( (error) => {
console.log( ‘ERROR’ );
console.log(error);
} );
}
function sendMessageToComponent(message) {
// send message to the HTML element
// console.log('sending message to htmldownloader: ’ + message.action);
$w( “#htmlDownloader” ).postMessage(message);
}
export function buttonFoodBank_click(event) {
//Add your code for this event here:
console.log( “downloading Food Bank data …” );
sendMessageToComponent({ action: “message” , payload: “foodbank” });
readDataCollection( “FoodBank” , $w( ‘#orgDropdownFoodBank’ ).value);
}
export function buttonProduce_click(event) {
//Add your code for this event here:
console.log( “downloading Produce data …” );
sendMessageToComponent({ action: “message” , payload: “produce” });
readDataCollection( “FreshProduce” , $w( ‘#orgDropdownFreshProduce’ ).value);
}
export function buttonMeal_click(event) {
console.log( “downloading Meal Program data …” );
sendMessageToComponent({ action: “message” , payload: “mealprogram” });
readDataCollection( “MealProgram” , $w( ‘#orgDropdownMealProgram’ ).value);
}
function readDataCollection(collection, orgName) {
wixData.query(collection)
.ascending( ‘organization’ )
.startsWith( ‘organization’ , orgName)
.limit( 1000 )
.find()
.then((result) => {
// console.log('result found: ');
// console.log(result);
dataToUpload = null ;
loadPage(result);
})
. catch ((error) => {
console.log( ‘No data retrieved / Error retrieving data. Check organization name, then contact NPX’ );
// console.log(error.stack);
});
}
function loadPage(queryResult) {
// console.log("loadingPage "+ queryResult.currentPage.toString());
if (!dataToUpload && queryResult.length > 0 ) {
dataToUpload = queryResult.items;
} else {
dataToUpload = dataToUpload.concat(queryResult.items);
}
if (queryResult.hasNext()) {
queryResult.next()
.then((result) => {
loadPage(result);
})
} else {
// Prep for download
// console.log(“Create payload for download”);
let jsonPayload = JSON.stringify(dataToUpload);
sendMessageToComponent({action: “data” , payload:jsonPayload});
}
}