Update data info into a collection & repeater

Hi everyone! Im having troubles at displaying and uptdating data information. I have a repetaer with some orders information, one of them is status order (pending, on process, completed).

I’m using wixdata.save and context The issue is that the item that gets the event creates a copy of it instead of updating the info, so the same order is getting duplicated on the repeater. Here is my code

export function completedBt_onClick((event) =>{
    $w('#c2').show();
    const itemId = event.context.itemId;  

    $w('#b1').onClick(() => {

        wixData.query("ErickHOrders")
        .eq("_id", itemId)
        .find()
        .then((results) => {

            let itemData = results.items[0];

            if(itemData._orderSt === 'In process' || itemData._orderSt === 'Urgent' ) {

            
                let toUpdate = {

                    "_client" : itemData.client,
                    "orderReference" :itemData. orderReference,
                    "_deliveryDate" : itemData.deliveryDate,
                    "_orderSt" : 'Completed',
                    "_billing" : itemData.billing,
                    "_paymentSt" : itemData.paymentSt,
                    "_spec" : itemData.spec,
                    "_piecesAmount" : itemData.piecesAmount,
                    "_unitValue" :itemData. unitValue,
                    "_totalValue" : itemData.totalValue,
                    "_productDescription" : itemData.productDescription

            }

            wixData.save("ErickHOrders", toUpdate)
            .then((results) => {
                ordersTrigger();
                $w('#c2').hide();

            
            })
            

    } // if brackets

    
})  // then brackets 
}) // Onclick brackets 

} // completedBt brackets 

In the repeteater i’m getting a duplicated values of all the orders that are in process status.

You forgot to INCLUDE the → _id <—
Without → _id <— it won’t work

If you would read the VELO-API-DOCS more careful, you wouldn’t ask this question anymore…

https://www.wix.com/velo/reference/wix-data/save

Save an item with a specified ID in a collection

import wixData from 'wix-data';

// ...

let toSave = {
  "_id":          "00001",
  "title":        "Mr.",
  "first_name":   "John",
  "last_name":    "Doe"
};

wixData.save("myCollection", toSave)
  .then((results) => {
    console.log(results); //see item below
 })
  .catch((err) => {
    console.log(err);
 });

Also it is NOT NEEDED, to generate the whole OBJECT again just to save it.

Use the already created RESULT-OBJECT itself and just do some adjustments on it, like…

you get → results ←
now you want to change (a) value(s) → inside → results / itemData ←

itemData._orderSt = "CHANGE-VALUE-HERE";
itemData.items.spec = "CHANGE-VALUE-HERE";

You already changed → 2-VALUES <— inside your Item-Data-Object.

Now just save it (object)…

wixData.save("myCollection", itemData)

But when i take a look onto your whole code, it shows me, that you are not that skilled.

-you are using the external functions, which are not the best choice
-you are declaring variables wrong, why???

You want to make a → SAVING - process <— but you declare your variable as → toUPDATE ???

OH, LOOK → there is also an → UPDATE-FUNCTION…

let toUpdate = { // to UPDATE??? SURE ???

Or here, this part of your code, should show you exactly what is not so good…

wixData.save("ErickHOrders", toUpdate)

At the first seconds, you will say → doesn’t matter, but when you are programming more complex codes you will love to see a good structured, organized and clean code.

Maybe one day, you will need some help from extern coders, like just right now and you present a code, which will lead the extern coder to think twice about all your written code, because parts of it won’t make any real sense.

Very glad about your answer! And for sure i’ll work on my code structure, logical process and analysis at the time of reading snip codes and tutorials.

Ever got your END-RESULT ?