Hello! Hoping you all can help.
I have a base of Store Locations (name, address, website) and a related table of Deals (details, participating store locations).
The Deals have a linked record field, Participating Store Locations, to attach one or more Store Locations records to each Deal.
I need to display a list of Deals with the details for each Participating Store Location like this:
DEAL 1
- Participating Store 1
- Participating Store 2
DEAL 2
- Participating Store 3
- Participating Store 4
- Participating Store 5
I can get a list of the Participating Store Location record IDs for the store locations from the linked record field.
I am having trouble getting the Store Location records returned from the find function. I think it has something to do with the timing of an asynchronous function.
I’ve tried a few things to make a callback or promise work but my javascript is thin in that area and I can’t get it to work.
Any help is greatly appreciated. Thanks!
Here is the code:
var storeLocationIDs = {};
var storeLocationRecords = s];
base('Deals').select({
maxRecords: 100,
view: "Active Deals"
}).eachPage(function page(records, fetchNextPage) {
records.forEach(function(record) {
storeLocationIDs = record.get('Participating Locations');
console.log('Participating Locations: ', storeLocationIDs ); // Displays IDs for participating locations
for ( i=0 ; i < storeLocationIDs.length ; i++ ) {
base('Store Locations').find(storeLocationIDsni], function(err, record) {
if (err) { console.error(err); return; }
storeLocationRecords.push(record);
console.log('storeLocationRecords = ', storeLocationRecords); // Displays record objects
});
};
});
fetchNextPage();
}, function done(err) {
if (err) { console.error(err); return; }
});
function listDeals () {
console.log('listDeals storeLocationRecords = ', storeLocationRecordso0]); // Displays UNDEFINED but expected first Record
};
listDeals ();