I have the following;
-
Collection of job applicants with collection ID: jobApplication072 currently with 11 entries.
-
The collection are individually indexed from 1 to 11 (number field). Field key is “index”
-
I put the collection on the page as #dataset1 but not connected. ( I think is optional to do this)
-
I have a text heading1 named “#collectionIndex” to show the maximum index number.
My code:
import wixData from ‘wix-data’;
$w.onReady( function () {
$w(“#dataset1”).onReady(() => {
populateCalculatedFields();
} );
function populateCalculatedFields() {
wixData.aggregate(“jobApplication072”)
.max(“index”)
.run()
.then( (results) => {
let index = results.items[0].indexMax;
console.log(index);
$w(‘#collectionIndex’).text =${index}
;
});
}
The above works in preview. The text box “#collectionIndex” shows 11 as recorded in the console. But when I publish the page, there is no result in the text box. I have also tried event handler using a button_onClick without the $w(“#dataset1”).onReady code:
export function buttonSvc_onClick(event) {
populateCalculatedFields();
} This code works in preview. Same when published: nothing.
Am I missing something? Hope to find solutions from the community. Thanks.