Fetching or Getting records from a Table based on ...
# 🤝help
c
I'm trying to retrieve records from my table using the execute code card but am having trouble finding a way to do so using a column that is not the recordID. # Things I have looked into: ## Using Get Record: For the getRecord method, as far as I can tell, I am only able to retrieve a record if I know it's recordId in advance. I can't get a record based on a different column. I can't seem to find an option to switch the unique id for a table from Record ID to something else. ## Using FindRecords I also looked into the findRecords method but that requires a query selector and I am unable to create a query selector that accepts a workflow variable as the input. (Also FYI: the video link for findRecords in the documentation page seems broken: https://botpress.com/docs/cloud/studio/tables/#findrecords). Can someone please help me with this? I'd be happy to provide any more information if required.
## Response I got from the general channel SimplyGreatGames — Today at 2:15 PM You can use an empty query selector : const recordData = await Character_DataTable.findRecords({}) It will give you the whole table Then you can loop through the records: workflow.recordsFound = [] // Get All Ability Records for (const ability of workflow.abilitiesInQuestion) { for (const record of recordData) { if (record.Name === ability) { console.log('Found Matching Record: ' + record.Name) workflow.recordsFound.push(record) } } } You can pull whatever column, in case I have a column called "Name" but it could be whatever your column is named, record.Type, record.Description, record.PhoneNumber, whatever Image SimplyGreatGames — Today at 2:23 PM Or you can wait because a new feature is supposed to be coming very soon so that you dont have to use execute card.
f
Hello @cool-summer-17043 is the work flow variable going to be from a defined set of options?
b
Hello , I have tha same problem. I have a table with a column called "conversationID", but I am not able to search the record, me code is like: const record = await MetadatasTable.findRecords({ offset: 0, conversationId}) but its isnt work.
c
@flat-plumber-75402 I'm not sure what you mean by defined set of options. If you are asking if the variable represents a categorical value then no, it's a number so I can't make query selectors based on categories. Please let me know if you meant something else.
@bulky-sunset-57003 If you see the answer SimplyGreatGames gave me, you basically have to fetch all the records and then filter the ones you want based on the value in your column of choice. If you have a very large table, it may make sense to make query selectors based on ranges (if that's possible for your use case) to reduce the number of records you need to filter through.
b
Ok thanks @cool-summer-17043 , you have any exemplo of how create a query?
c
@bulky-sunset-57003 Are you asking for an example on how to create a query selector? You add query selectors on the right tab when you open a table
3 Views