Update a dataset row using wix.data update on a dynamic page

Hi,

I’m struggling to get over this last hurdle on what’s been a fun but challenging introduction to velo!

The site has dynamic pages that display fire doors for inspection and will be used to log quarterly inspections. My first dataset will show a permanent record of all surveys but I also want a separate data set for use an asset list that shows the current status and last inspection date of all doors.

I’m struggling to understand how to look for the right row (dependent on the door page) and then update just that row when a new survey is submitted. Date and inspection status would be updated. Screenshots below.

The assumption is I need to use the update function on wix data but I’m unsure how to filter using the #doorNo text on the dynamic page to update the relevant row?

Hoping someone can help :pray:

An ordinary simple query…

import wixData from 'wix-data';

$w.onReady(function () {
    xxx();
});

function xxx() {
    wixData.query("myCollectionIDhere")
    .find()
    .then((results) => {
        if(results.items.length > 0) {
            console.log("My-Found-Results: ", results.items);
        } else {  }
    })
    .catch((err)=> {console.log(err);});
}

Adding filter-options to your ordinary-query…(example)…

import wixData from 'wix-data';

$w.onReady(function () {
    xxx();
});

function xxx() {
    wixData.query("myCollectionIDhere")
.eq("dbFieldID", "value")
.contains("dbFieldID", "value")
.hasSome("dbFieldID", ["value1", "value2", "value3"...])
.hasAll("dbFieldID", ["value1", "value2", "value3",...])
    .find()
    .then((results) => {
        if(results.items.length > 0) {
            console.log("My-Found-Results: ", results.items);
        } else {  }
    })
    .catch((err)=> {console.log(err);});
}

Here you get the results…

    ...
    ...
    .find()
    .then((results) => {
        if(results.items.length > 0) {
           console.log("My-Found-Results: ", results.items);
        } else {  }
     ...
     ...
     ...

But what exactly you want to UPDATE ? Of course the found and modified data, right?

...
    .find()
    .then((results) => {
        if(results.items.length > 0) {
           console.log("My-Found-Results: ", results.items);
           let items = results.items
           
           //changing for example TITLE ...
           items[0].title = "xxxxxxxx";
          
        } else {  }
     ...

Updating …

let options = {
  "suppressAuth": true,
  "suppressHooks": true
};

wixData.update("myCollection", items[0], options)
    .then((results) => {console.log(results);})
    .catch((err) => {console.log(err);
});

…or BULK-UPDATE…

wixData.bulkUpdate("myCollection", items, options)
    .then((results) => {console.log(results);})
    .catch((err) => {console.log(err);
});

Working on a DYNAMIC-DATASET…

$w.onReady(function() {
  $w('#dynamicDataset').onReady(()=>{
     let curItem = $w('#dynamicDataset').getCurrentItem();
     console.log("My-Current-Item-Data: ", curItem);  
     console.log(curItem.title); 
     console.log(curItem._id);
     console.log(curItem._owner);     
   });
});

Take a look onto all this and try to generate your code out of the shown example-parts.

Thanks so much for laying it out like that, makes it so much easier to get a grasp of the method.

Appreciate your help and hopefully update the post with the final code if I can get it working :crossed_fingers: