This code works when in preview mode but does not work when published, could some one explain please?

$w.onReady(function () {
 //this is to help find the dynamic page
 let project = $w("#projectName2").text;
 //filter based on name of dropdown selected and selecting the dynamic page name
 let filter = wixData.filter().eq("dropdownField2", project);

//create a sum of the total donations
    wixData.aggregate("donationForm022").filter(filter).sum("paymentField", "sumD").run().then( 
 (result) => {
 let total = result.items[0].sumD;
            $w('#sumD').text = total.toString();


any advice would be greatly appreciated.

  1. Did you sync your Preview with Live? (Sandbox-DB with live-DB)?
  2. Did you gave your DATABASE the right permissions?
  1. I’m sure I synced sandbox-db with the live-db as i can see all the data in live
  2. what permission would I give this database as it is a donations database?

For testing you can —> downgrade your DB permission-security for a short time-period to → “everyone” (just for testing).

If it works with dowgraded permission, than you will know, whats the problem.

If you have sensitive data in your DB, than of course you should set your DB-permissions to a higher level.

I have tried changing the permissions to everyone, but unfortunately this still does not work.

And your DATA in your LIVE-DB and PREVIEW-DB are surely identical?
Hmmm, sounds strange. Then i have no other idea, for you sorry.

Did you take a look into your console? Do you get some errors?

I just saw an error message which I did not see before which says:
Cannot read property ‘sumD’ of undefined

Also thank you so much for your time and help

Then you have, right now, found the → PROBLEM! → ( ‘sumD’ =undefined)!
Now try to figure out —> why is —> ‘sumD’ = undefined?

well sumD is the ID for where the sum will be printed on the website page (so a text box), so I’m a bit confused why it is saying it is undefined