Problem assigning aggregate query result to form element value

@Yisrael

Hi Yisrael,

Sorry to bother you once more, but I have followed your TodoList example and I can see how it is a much better way to achieve what I need, however, I have now spent near 2 fuul days trying to resolve this new problem. Any chance you could have a look and advise where I am going wrong here? Thank you in advance.

I am trying to assign the value from the following aggregate query :

async function maxRSVPID(event) {
await wixData.aggregate(“RSVPYvonneandJosh”)
.descending(“rsvpid”)
.max(“rsvpid”)
.run()
.then( (results) => {
let items = results.items[0];
console.log(results)
$w(’ #maxRSVPID ').value=items }) }

It seems to me that the query is returning the correct result, as below, but I cannot get the value , being 2 in this instance, to populate #maxRSVPID on the form. I have tried using a textbox as well as input (which is what the element currently is) and everything is of a number type. What am I doing wrong??

Full page code is below:-

import wixlocation from ‘wix-location’;
import wixData from ‘wix-data’;

$w.onReady( function () {

});

export function RSVPS_ready(event) {
maxRSVPID()
}

export async function btnNext_click(event) {
wixData.query(“RSVPYvonneandJosh”)
.eq(“email”, $w(‘#emailaddr’).value)
.find()
.then( (results) => {
if (results.items.length > 0) {
$w(‘#emailerrorgrp’).expand();
} else {

  $w('#emailmsg').collapse(); 
  $w('#instructions').expand(); 
  $w('#guestaddgrp').expand(); 
  $w('#btnaddguest').expand(); 
 } 

} )
}

export async function btnaddguest_click(event) {
let emailid=$w(‘#emailaddr’).value
await $w(‘#addRSVPS’).save();
$w(‘#repeaterheader’).expand();
$w(‘#repeater1’).expand();
$w(‘#firstnameinput’).value=“”
$w(‘#surnameinput’).value=“”
$w(‘#responseinput’).value=“”
$w(‘#allergiesinput’).value=“”
$w(‘#songsinput’).value=“”
$w(‘#emailaddr’).value=emailid
}

export function tryagain_click(event) {
$w(‘#emailaddr’).value=“”
$w(‘#emailerrorgrp’).collapse()
$w(‘#emailmsg’).expand();
$w(‘#instructions’).collapse();
}

export async function btnsubmit_click(event) {
let emailid=$w(‘#emailaddr’).value
await $w(‘#addRSVPS’).save();
$w(‘#firstnameinput’).value=“”
$w(‘#surnameinput’).value=“”
$w(‘#responseinput’).value=“”
$w(‘#allergiesinput’).value=“”
$w(‘#songsinput’).value=“”
$w(‘#emailaddr’).value=emailid
}

function setRSVPIDfilter() {
let value = $w(“#maxRSVPID”).value;
let filter = wixData.filter();
$w(“#RSVPS”).setFilter(
filter.eq(“rsvpid”, value)
);

}
async function savecollection(event) {
let $item = $w.at(event);
await $item(‘#RSVPS’).save();
}

async function maxRSVPID(event) {
await wixData.aggregate(“RSVPYvonneandJosh”)
.descending(“rsvpid”)
.max(“rsvpid”)
.run()
.then( (results) => {
let items = results.items[0];
console.log(results)
$w(‘#maxRSVPID’).value=items
});
}