After .onRowSelect, the record's id is 'undefined'

I have a collection, where the record is found via a ‘name match’. The correct record is found and displayed. All is good. But, I would like to update the record with with new data for some fields. I see there are various ways to do this. I figured the easiest was to update the record using the _id. But, I haven’t been able to get it! What am I doing wrong???

$w( “#searchButton” ).onClick ((event) =>{
wixData.query( “HLAMemberDB” )
.contains( “name” ,$w( ‘#searchBox’ ).value)
.find()
.then(result => {
console.log( “searchButton onClick event” , result);
$w( “#table1” ).rows = result.items;
$w( “#table1” ).expand();
$w( “#table1” ).show( ‘fade’ );
})

$w( “#table1” ).onRowSelect( async (row_choosen) => {
let rowData = await row_choosen.rowData;
let rowIndex = await row_choosen.rowIndex;
console.log( "rowData is " ,rowData);
console.log( "RowIndex is " ,rowIndex);

    console.log( "_id is " ,rowData._id);   <------  THIS SAYS "undefined" 
    console.log(rowData.lakeAddress);	      Everything else is good. 
    console.log(rowData.parcelNumber); 
    console.log(rowData.name); 
    console.log(rowData.mailAddress); 
    console.log(rowData.city); 
    console.log(rowData.state); 
    console.log(rowData.zip);

How do looks like the console-log-output for your row-data?
Do you have a screenshot?

your code doesn’t match the console, in picture it is _ID but in the posted code it is _id. can you expand the “rowData is” object?

@jay65866 I noticed that the code didn’t match the output, too. I think that the _ID is the only difference. I have attached the updated code and the output you requested. Thank you very much for looking at this!

@karenmpiekarski have you tried using options to suppress auth see if this helps

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

However I think the issue might be in the return onrowselect; maybe adding the below to the top of the data query return:


EDIT: refactored code:

wixData.query("HLAMemberDB")         
 .contains("name", $w('#searchBox').value)         
 .find(options)         
 .then(result => {             
  
    let items = result.items;
    items.forEach( (item)=>{ item.row_id = item._id; }); <- copy _id to row_id;
  
     console.log("searchButton onClick event", {result, items});             
     $w("#table1").rows = items;             
     $w("#table1").expand();             
     $w("#table1").show('fade');        
  });


 $w("#table1").onRowSelect(async(row_choosen) => {
    let rowData = await row_choosen.rowData; 
    let rowIndex = await row_choosen.rowIndex;
        console.log("rowData is ",rowData); 
        console.log("RowIndex is ",rowIndex); 
 
        console.log("_id is ",rowData._id);
        console.log("row_id is ",rowData.row_id);
        console.log(rowData.lakeAddress);      
        console.log(rowData.parcelNumber);
        console.log(rowData.name);
        console.log(rowData.mailAddress);
        console.log(rowData.city);
        console.log(rowData.state);
        console.log(rowData.zip);


      });

of course, this isn’t tested so there may be some syntax errors etc;

@jay65866

I’ve got to tell you, I’m not sure happened. I did what you said and didn’t see any change. Then, I clicked on

searchButton onClick event {…} Table Copy JSON
_items: Array(1) Table Copy JSON
0: {…} <—clicked here and got this:
{…}
json Table Copy JSON
city: “OAKWOOD”
name: “Doe Jane”
zip: “45873”
state: “OH”
_id: “44e4a2c8-1d6b-4ae5-9753-b895c591b3f5”
_owner: “1aac432e-cdc2-4f2f-8c31-833a4d3eebf7”
parcelNumber: “76-10-27-000-030.030-009”
_createdDate: “Fri Mar 12 2021 14:19:41 GMT-0500 (Eastern Standard Time)”
_updatedDate: “Sat Mar 13 2021 12:58:18 GMT-0500 (Eastern Standard Time)”
lakeAddress: “480 LN 120EA HAMILTON LK”
mailAddress: “100 State St”
row_id: “44e4a2c8-1d6b-4ae5-9753-b895c591b3f5”

java test Line 30
rowData is {…}
json Table Copy JSON
lakeAddress: “480 LN 120EA HAMILTON LK”
parcelNumber: “76-10-27-000-030.030-009”
name: “Doe Jane”
mailAddress: “100 State St”
city: “OAKWOOD”
state: “OH”
zip: “45873”
java test Line 46

RowIndex is 0
java test Line 47
row_id is undefined
java test Line 49
_id is undefined
java test Line 50
480 LN 120EA HAMILTON LK
java test Line 51
76-10-27-000-030.030-009
java test Line 52
Doe Jane
java test Line 53
100 State St
java test Line 54
OAKWOOD

So, I have the correct _id. Thank you! I just don’t quite understand why we had to do what we did! Thank you SO much. I appreciate your time.

@karenmpiekarski Hey, no worries. although it looks like you still didn’t get your _id value (or row_id as we put it) within the TableRowSelect function.

java test Line 47  row_id is  undefined 
java test Line 49  _id is  undefined

at a guess, It seems the row_choosen provided by the function is only returning the actual column values from your table.

However if you actually only wanted to be able to see just the _id in the console you could add:
console.log(items[0]._id);

regards

@jay65866 I hope you are still out there to help me. I have been trying to get the value of the _id in a variable so I can use it to update some fields in the collection. I can get it displayed on the console, but I can’t get the id I need ([1], in this case) to a variable. When I display ids, I get one character. Please help. It is in JSON array, but I haven’t figured out out to retrieve it. Thank you in advance.

Here are the screen shots and the console log:

@karenmpiekarski
Yes, i am still out here, but at moment totally OVERLOAD with own projects.
This is why i am not really available here in forum, sorry.

But i will try to take a closer look onto your problem during the next week.

@russian-dima should I just start a new post so someone else can pick it up? Let me know… thanks!

@karenmpiekarski
No i think you do not have to open a NEW post, because everybody can read this one. And if there is someone who wants to help, he/she will do it here in this post.

@karenmpiekarski
Can you post a little excerpt of your related DATABASE (with visible ID-Field+Owner-Field) in a screenshot?

@russian-dima , let me know if you need anything else. (and thanks!)

@karenmpiekarski
While i was waiting for your reply, i already prepared something for you…:grin:
I don’t know if this example will fit your issue to 100%, but perhaps it will be able to let you understand things a little bit better.

Take a look here…
https://www.media-junkie.com/pflegeservice

You will find a —> TABLE on this site, where you will have some DATA in it.
I created a quick example with the MAIN-DATABSE…

How to use this example?

  1. Load the → “Main-DATABASE”
  2. Click on one of the rows in the table below.
  3. A new menu-window should appear.


Pay attention!!! ----> At this point you already get some messages in your CONSOLE!

  1. Click on —> “Edit-Item”
  2. A new menu-window should open again…


6) Now you should be able to create CODE for the UPDATE/SAVE-Feature (by clicking onto → “SAVE”) and save data back to your DATABASE.

As you can see, it also shows the —> ID <— of the current selected row in the CONSOLE.

And here all the CODE which was used for this example…

var myDATA 

export function table1_rowSelect(event) {
    console.log(event)
    $w('#BTNeditItem').enable()
    myDATA=event
}

export function BTNeditItem_click(event) {
    console.log("myDATA = ", myDATA.rowData)
    console.log("-------------------------")
    console.log("myDATA = ", myDATA.rowData._id)
    console.log("Salutation = ", myDATA.rowData.anrede)
    console.log("First-Name = ", myDATA.rowData.vorname)
    console.log("Last-Name = ", myDATA.rowData.name)
    console.log("Status = ", myDATA.rowData.status)
 //------------------------------------------------
    $w('#input1').value = myDATA.rowData.anrede
    $w('#input2').value = myDATA.rowData.vorname
    $w('#input3').value = myDATA.rowData.name
    $w('#input4').value = myDATA.rowData.status
 //------------------------------------------------
    $w('#columnStrip1').expand(), $w('#columnStrip1').show('fade')
}

All you have to do now, is to code the save-function.
What should happen —> when press on —> “SAVE”-button?

And by the way, i did recognize just right now, that you have tagged/marked —> @jay and not me :sweat_smile::sweat_smile::sweat_smile: (sorry) :joy: in your post.

@jay I hope you are still out there to help me.

@russian-dima , I laughed when I saw your last post…because I didn’t realize it was Jay’s either (we are going to give him a complex or something!).

Thanks for staying on. I am not sure how to see the console output (in your mediajunkie.com example). That would help. Thanks…

@karenmpiekarski
Sorry for Jay. :see_no_evil: Was accidently!

Back to your question.
You can use the CONSOLE of —> for example in CHROME-BROWSER.
Press F-12 and navigate to → CONSEOLE.

And before you try to analyse some results in CONSOLE, first reset the console completely, because this example is already got so complex, so that there are also some unwanted bugs, which normaly should not throwing ERRORs, but they does. —> So first reset the console.

@russian-dima , I looked at your example. Maybe if I had the source code (or more of it), I would get it, but I don’t understand how “myDATA = event” gets any of the table data…

Can you point me somewhere so I can figure it out?