How to get the ID of an inserted record (tables)
# 🤝help
s
in one node of my bot, i generate a quote for the user, once the quote is generated, i want the quote info to be stored in the table. the user then picks whether or not they want to proceed with the quote as an order and one of the options is to add another product (ie a second quote). At this point in time, i would like for the bot to prompt the user for contact info and update the record created a few nodes earlier around the quote with their contact info. my problem is that when i attempt to "update record," the only way to designate which record i am trying to update is by using the unique id, however, i do not know the unique ID and in fact, this information will be dynamic, will it not? how do i store the record ID upon creation in a variable in order to call it in the update record card? Or is there a better way to do this?
a
@rich-battery-69172
s
what i want to be able to do is to have the user give me data for multiple quotes/ multiple products and then i present them an itemized total quote
m
I would like to know exactly the same thing, I need to update a record that was created earlier in the conversation but I can't find the RecordID.
r
Hey I'm a bit confused, the insertRecord function already returns the recordId. I'm probbaly missing something?
Copy code
const record = await Data1Table.createRecord(payload)
workflow.yourAddedRecord = record.id // stores the record ID in a workflow variable
While this code in theory works it is really not efficient. It makes a request for every possible row combination ,essentially scanning your whole table every time. You could use
const batch = await Data1Table.findRecords({ limit: 1000, offset: 0 })
to get 1000 rows at a time instead, then use
.find
in the result to find the row with the property you are seeking/
i
Hey Sly. Thanks a bunch for sharing this code! It is exactly what I needed. Much appreciated!
348 Views