Sum of Database values with a filter (Data from DynamicPage)

Hello.

FYI - I have Zero coding knowledge. Whatever i have written here is just 2 weeks of reading, back and forth. I apologize for silly syntax errors.

I’m running a website where the RSVP button has to be disabled once the required seats are filled up.

2 Collections

  • a) Screenings - All screening details
  • b)RSVP - User information being stored

RSVP button is on ‘ScreeningsTItle’ page (Dynamic Page - Screenings Dataset) with all info including venue details.
Input forms are on ‘Screenings RSVP’ (Dynamic Page - Screenings Dataset) - with Venue details input based on which venue page they came from.

I’m trying to sum up the total no. of seats (“Guests” field) but this has to be filtered by each venue -

I can’t seem to get this to work.

Right now I’m looking to only understand how to create a filter - and later worry about setting up a count/summation to enable/disable RSVP Button.

FullCode here -

$w.onReady( function () {
let currentItem = $w(‘#dynamicDataset’).getCurrentItem();

// RSVP ENABLE using Boolean in Dynamic Dataset, checkbox in collection
if (currentItem.rsvpboolean === true ){
$w(‘#button5’).enable();
}

//RSVP Button Redirect
$w(‘#button5’).link = “/Screenings/” + currentItem.title + “/rsvp”;

//Facebook Event button Enable
if (currentItem.eventYes){
$w(“#button1”).enable();
}

//creating query
// Why can’t I call information from Dynamic Dataset?

let RSVPVenue = currentItem.venue;
wixData.query(“RSVP”).eq(“title”, RSVPVenue.value)
.find()
.then((results) => {
let items = results.items
console.log(items)
})

// Query for filtering out guests who have entered value 1 - WORKS
//Only for testing, example code

wixData.query("RSVP").eq("guests", 1) 
    .find() 
    .then((results) => { 

let test = results.length
console.log(test)
})

});

Try this one

  $w("#dynamicDataset").onReady( () => { // Make sure it is loaded
    let currentItem = $w('#dynamicDataset').getCurrentItem();
    wixData.query("RSVP").eq("title", currentItem.venue)         
    .find()         
    .then((results) => {  
      let items = results.items; // All items           
      console.log(items);
      let guests = 0;
      items.forEach((record) => {
        guests = guests + record.guests;
      })
      console.log("Nr of guests for this is:" + guests);         
    })
  });

Hey. This worked. Thank you for the code for the loop to count total no. of guests. I have incorporated it into the 'if loop". Works like a charm.

I wonder why it didn’t work even when I used “RSVPVenue” as variable (even before i used RSVPVenue.value - which I assume is wrong) - for currentItem.venue as opposed to just currentItem.venue.
Anyway,
Thanks so much.

Just to learn more - is there some way with which I can make the RSVP button disable if
Current date/time is past the screening Date/Time? So I can make it fully Auto and not rely on the RSVP checkbox like I do now?

import wixData from ‘wix-data’;
$w.onReady(() => {
Sum_amount();
});
export function Sum_amount(){
wixData.aggregate(“OngoingProjects”) // instead I wanna use $w ( ’ #dataset6 ’ ). onReady ( () => {
.sum(“outstandingAmount”,“sumamount”)
.run()
.then( (results) => {
$w(’ #text310 ').text = results.items[0].sumamount.toString();

This code works but I want to use with #dataset6 on ready function. Not able to do so. Please help