Save Object should update an existing row but incorrectly adds a new row

Hu
On my page I have 3 selects and an Text Area. I use the Selects to locate a row in a table to edit.

When I edit the Text Area and hit the Save button, I get a new row instead of updating the existing row. I force objectId to be a part of the object to update, still does not work.

The Save Button On Click is…

image

How do I update an existing row?
BruceX

Hello @Bruce_X

When you load table objects, you get a list of items(even if page size = 1). When you set property Annotation, you set it to list (good to know - list in JS too have properties). So when you saving it to DB it’s a list with property, not an existing row with the changed property.

How to fix it? You need to get the first item, from varAnnotations list, and after this save it to the database.

You can debug it, with Print block, and watch what you try to save in the browser console(F12), your object should have an objectId in this case you patch your existing record in DB.

Regards, Dima.

Thank you Dima, I suspected I was getting a list from ‘Load Table Objects’.

I have attempted to follow your advice but I do not think I have it right. I got the first item in the list (varAnnotations) but how do I turn it into something than can be saved back to the row that it came from?

image

BruceX

You need to get the first item on the list, and after that change a property and save.

Regards, Dima.

Hi Dima
I believe I am getting the first item in the list because with the below arrangement of jigsaws, the edited value in the list is being saved, just in the wrong row.
To be clear, this is my page…

image

And this what I end up with in the database with the below logic

image

The logic that does this is …
image

How do I get the edited value into the correct row???

My apologies for being a newbee, but you may need to be very explicit with your answer.

Kind Regards
BruceX

How works Save Object in Backendless block:

  • if saving object have objectId property - we rewrite existing object
  • if saving object have unexisting in table objectId property - we catch an error
  • if saving object haven’t objectId - we create new record in the table

You don’t save objects at another existed row, you create a new row.

So, your algorithm must be like this:

  • Retrieve objects from the table
  • Get only one object from the list
  • Change him
  • Save to backendless

Unfortunately, but we couldn t always solve your issue fully, but we can give a tip, or solve an issue if its looks like a bug.

Please, read our documentation and youtube playlist about backendless before creating an support topic.

Regards, Dima.

Dima

I did know everything that you said except for the last bullet point of your reply, which I had asked for ‘how to do’ 3 times. My explanations and examples showed that. I am happy if you simply point me relevant documentation or tutorial that would tell me the answer to the specific question I am asking.

Anyhow, after much experimenting I have solved it. The logic I had, needed 4 extra blocks to work. Now I know how this sort of thing works.

Dima, I hope we are ok because I am onto the next thing now.

Kind Regards
BruceX

Hi Bruce,

You’re welcome to post your questions and comments any time! :slight_smile:

Regards,
Mark