I have some code that was working perfectly to pull data from a database to a chartjs chart on a dynamic page until yesterday. Now it just pulls data from one item and all pages show the same data. Its killing me.
The code works on another page. Is it something to do with the database? It only started happening after I added some more fields in database.
Now Ive tried so many things, maybe I’ve changed the code. I have no idea.
$w.onReady(() =>{
$w( “#dataset1” ).onReady( function () {
let valueadded = $w( “#dataset1” ).getCurrentItem().valueAddedLast5Years;
$w( “#html1” ).postMessage(valueadded);
$w( “#html1” ).onMessage((event)=>{
if (event.data.type === ‘ready’ ){
$w( “#html1” ).postMessage(valueadded);
}})
})})
Try changing your code around at the start with the page and dataset onReady functions to something like this…
$w.onReady( () => {
$w("#dataset1").onReady( () => {
let valueadded = $w("#dataset1").getCurrentItem().valueAddedLast5Years;
$w("#html1").postMessage(valueadded); $w("#html1").onMessage((event)=>{
if(event.data.type === 'ready'){ $w("#html1").postMessage(valueadded);
}
//rest of code//
It looks like you have used this example.
Adding more fields to the dataset itself should not make a difference as you are telling what field to get the info from in your code with this line here.
let valueadded = $w("#dataset1").getCurrentItem().valueAddedLast5Years;
As long as the field key of the field that you are using is ‘valueAddedLast5Years’, then it should stay reading from that field.
As you have added new fields, have you made sure that you have synced your dataset so that the changes apply to both your sandbox and live versions?
Thanks for the response to this. I realised eventually I wasnt referencing the dynamic database, just a generic one><