Hi!
I’m outlining a bit here since as of this writing, only see a few topics related to the selectRecordsAsync
method. Hoping this is helpful to someone else!
GOAL
My goal here is to update a value in a record selected by the user (e.g. {"Status": "Not Started"} -> {"Status": "In Progress"}
). User first selects a record with await input.recordAsync
and then the record is updated with updateRecordAsync(fieldId, {"key": "value"})
).
BACKGROUND & ATTEMPT 1
First - a sanity check and quick background on my approach here.
As part of this, I don’t need to/want to present a list of all records. For example, I have about 50 records in total, but only about 10 are relevant, and thus only the 10 should be presented to the user for selection.
Since you can render the input.recordAsync
from a view, I started by creating a view which is configured how I want it w/ filters, sorting, etc, so that only the 10 records I want are listed. And voila - the input.recordAsync
presented just the 10 options. Easy peasy.
But, when it was time to implement the update methodology, I was getting an id error. Basically, I learned that the id
value from a view is different from the id
value from the underlying record and table, which, I guess makes sense! For posterity: the view id vals are prepended w/ sel
while those from a table are prepended w/ rec
.
All of this is to say, doesn’t seem like you can prompt a user to select a record from a view and update the underlying table, at least as far as I can tell, without some hackiness…right?? Would be curious if I am way off here.
ATTEMPT 2
So - I pivoted to using the selectRecordsAsync()
method from the underlying table with all 50 of the records. Figured I could just use .filter()
and pass the resulting 10 records I want to the input.recordAsync
call.
But, as a default, selectRecordsAsync()
returns only the id
and name
fields for each record. I referred to the documentation (pasted below), and figured I could pass an array of field names as an options.fields
argument, and the method would return the record objects with these fields included. Like so:
let query = await tasksTable.selectRecordsAsync({
fields: f'Task', 'Status', 'Client', 'Project']
});
output.inspect(query);
But this is not returning anything different and is not throwing any errors.
I checked this post, and understand I can use getCellValue()
to retrieve other values, but it seems clunky if I need to filter on 5 or 6 parameters, for example.
Here is the documentation I referenced:
QUESTION
So, what is the recommended approach for filtering table records by a number of values in that table? Am I using the selectRecordsAsync()
call correctly?