Help

This Product Ideas board is currently undergoing updates, but please continue to submit your ideas.

Feature Request: Extend API to table.currentView()

cancel
Showing results for 
Search instead for 
Did you mean: 
Zollie
10 - Mercury
10 - Mercury

session.activeViewIds would return all of the tablesโ€™ active viewIds

Use Case
Iโ€™m prompting users for a couple view names in a script, but that seems unnecessary since the views users choose will likely be whatever their active views are. The views are meant to act as filters for which records are involved for the script. But itโ€™s not ideal to be prompting for views if there are eventually a lot of views in use (and therefore a large single select to scroll through).

What Iโ€™ve Tried
Itโ€™s possible to get all the view IDโ€™s, the current tableโ€™s active view ID, as well as view IDโ€™s already known by name - but those donโ€™t help because of the italicized words.

Example
Letโ€™s say I have a base with two tables (Apples and Oranges) and a bunch of views in them. The Apples table is currently set to โ€œZollieโ€™s Apple Viewโ€ and the Oranges are set to โ€œZollieโ€™s Orange View.โ€ Iโ€™d like to return the view ID for both of those Views, without returning any others.

7 Comments
Dominik_Bosnjak
10 - Mercury
10 - Mercury

If Iโ€™m understanding you correctly, this has been doable since the early days of the Scripting app/block:

const currentView = base.getTable(cursor.activeTableId).getView(cursor.activeViewId);
console.log(currentView);

Itโ€™s possible to get all the view IDโ€™s, the current tableโ€™s active view ID, as well as view IDโ€™s already known by name - but those donโ€™t help because of the italicized words.

Iโ€™m not sure what formatting has to do with anything? You can easily pull cursor data, and the same goes for manipulating most base metadata, view configurations very much included:

output.markdown(`# Your current active view is **${base.getTable(cursor.activeTableId).getView(cursor.activeViewId).name}**`);

base.tables.map(t=>t={table:t.name,views:t.views.map(v=>v.name)})
    .map(obj => {
    output.markdown(`#### All views in table ${obj.table}`);
    obj.views.map(v=>output.markdown(`- ${v}`))
    });
Zollie
10 - Mercury
10 - Mercury

Thanks for taking a look @Dominik_Bosnjak, these are some of the insufficient solutions I was referencing. The goal is to get active views from multiple tables.

The first solution (const currentView) is insufficient because it only pulls the active view from the current table - where as I need them from multiple tables.

The second solution satisfies the opposite. It pulls all of the tablesโ€™ views, but includes inactive views as well - whereas I only want the active ones.

The API seems to think of โ€˜activeโ€™ through the lens of a โ€˜cursor.โ€™ But I would argue, whichever view is set in a table (even if not on-screen) should be considered active if thought of through the lens of a โ€˜session.โ€™

Dominik_Bosnjak
10 - Mercury
10 - Mercury

Hmm, okie, could you define what constitutes an โ€œactiveโ€ view? Because thereโ€™s only ever one of those, and unfortunately, I donโ€™t think itโ€™s possible to send delayed cursor queries. That is to say, you can definitely timeout your requests but the Scripting block caches this information if memory serves correctly, so asking for repeated input from the user is the only way to go if you arenโ€™t willing to build a custom app.

With all of that said, this would be the time to rethink your overall plan. Whatever it is youโ€™re trying to do, I guarantee thereโ€™s a better way, likely even within the confines of the Scripting app.

Views are just fitered record arrays (or queryRecordResult instances, if you will). Whatever data they might hold that youโ€™re after is bound to be more acceessible from another angle.

Zollie
10 - Mercury
10 - Mercury

By active, I mean the โ€œviews that are currently set.โ€ I agree โ€˜API.cursorโ€™ is not the correct way (cursor only refers to whatโ€™s on-screen).

I also want to emphasize, Iโ€™m well aware this isnโ€™t possible as Iโ€™d like, which is why this is tagged as a product suggestion.

This is just a simple scripting block. Again, I already have a working solution - prompting users for views. But since users are already familiar with views, they use them frequently, maybe we should be able to use them for queries regardless of cursor context.

Kamille_Parks
16 - Uranus
16 - Uranus

Iโ€™m not quite getting this. Either a view is active by the current user or its not. Are you asking for an array of all views the current user has opened since the start of this session (base first loads)?

Zollie
10 - Mercury
10 - Mercury

The idea is if you open any of your given bases, which views are currently set in each table? So maybe Session isnโ€™t a good word either, since it would extend beyond a given session.

In any case, hereโ€™s an example,

Table Name:            Table1  Table2  Table3
User's Current View:   View21  View24  View74

Iโ€™d like to be able to query

base.getTable("Table2").getCurrentView()
=> View24

regardless of user context (which table the user is looking at)

Bill_French
17 - Neptune
17 - Neptune

I think what heโ€™s saying is that given a collection of tables in a base, the user is able to select views for each table that are โ€œselectedโ€; ergo - active on that table. Ergo, there is the potential for as many โ€œactiveโ€ views as there are tables in a base. In fact, there are always at least one view used by every table all the time, right?