Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Feb 13, 2020 08:58 AM
I see that you can get all records from a table or view - and even sort them. But what if you want a subset - for example all those records connected to another record? It’s not always possible or desirable to create views for this type of thing?
Feb 13, 2020 09:44 AM
Presumably you can do that filtering with JavaScript on the set of all records. I don’t know exactly how it might go, but perhaps something like:
records = table.selectRecordsAsync();
filteredRecords = [];
records.map(record => ({
if (record.getCellValue("Cell to Check") === "Desired Value")
filteredRecords.push(record);
}));
:man_shrugging:t2: I’m not great with JavaScript, but I think that should work
Feb 13, 2020 10:23 AM
Um, the API does support filter queries that use every-day formula constructs. This eliminates the need for special views to pare down the result sets.
Feb 13, 2020 11:25 AM
Yep, echoing @Jeremy_Oglesby – you can select the records from a table or view, then filter them in your code. Here’s a similar snippet, but showing how to do it from a specific view and filter down to records where the “Name” field is longer than 5 characters:
let query = await view.selectRecordsAsync();
let filteredRecords = query.records.filter(record => {
let name = record.getCellValue('Name');
return name !== null && name.length > 5
});
Since the scripting block runs inside your base, it uses a slightly different mechanism than the public API. So right now it doesn’t support filterByFormula
queries, but it can quickly load all the records in a table or view instead.
Feb 13, 2020 11:35 AM
@Kasra, thanks for this guide-point.
To be clear, are there any memory or other client-side constraints at scale when loading all records and forcing the client to deal with the burden of filtering?
Feb 13, 2020 12:39 PM
We’re going to keep an eye on real-world constraints and resource usage—if you hit memory limits in extremely large tables let us know!
Feb 13, 2020 01:20 PM
I’ll take that as a “Yes”.
Feb 14, 2020 11:22 AM
Another question - is there a way to apply typecast=true in the Scripting Block when writing a record or group of records.
Feb 14, 2020 11:50 AM
Typecast isn’t supported in the scripting block right now. Out of curiosity, can you share more about your use case for typecast – e.g. is it mainly the convenience of automatically creating linked records?
Feb 14, 2020 03:44 PM
Imagine a block that auto-tags content; this post explains it in detail, the Cliff-notes follow.
{typecase : true}
.Ergo, the only way to do this is to push the tags into a text field, and then change the field type to a multi-select after running. Aside from the absurdity of this post-tagging manual process, it prohibits future tagging on new records where new tag values may naturally and predictably occur.
As you can see, this is a show-stopper to using NLP to magically tag content in an integrated fashion and forces me right back to an external API process.