I would like to add a new record to a related table using an API. How can I input the values for the related fields?
{field:“col_572342”,data:RowId} unable to succeed
Hi @ulysseschiu , welcome to spreadsheet.com community. Thanks for reaching out.
There won’t be primary key value for the new record until you create that record/row in related sheet. so you should create record/data in related sheet first and then do create/update record in original sheet, with the primary key value of the newly created record.
For example: I have table A and table B, they are related
I have a data D1 in table A, if I want to use the API to add a new data D2 associated with D1 in table B
practice:
- I first add D2 to table B and get the rowid of D2
- Update the associated column col_572342 in D1 using the syntax {field: “col_572342”, data:rowid}
Is the above approach correct?
Yes approach is correct, But you need to pass related sheets primary key value instead of rowId. Please see the screenshot (col-A is primary col in Table B). So after creating record in Table B. You will have primary key value of that row in col-A(For eg:12th row’s primary key value is 8). Pass that value in place of data instead of rowId in 2nd step.
{
“field”: “col_572342”,
“data”: “8”
}
It’s work
Thank you~