Create Record under View - Default Values

Good morning all :coffee:

My example base - a score board :joystick:

There’s a neat trick that not too many casual Airtable users know about - where by configuring filters within a new view that’s filtered to Single Select column(s), that new records created under that view will default to the filtered value(s). Very handy!

  1. Have the Single Select Field (or more)
  2. Create the View
  3. Filter that View to Single Select colums
  4. New records created default to those values.

My question - is it possible to POST a record to a targeted View? Obviously the API calls for the Base ID and Table target, but I can’t find anywhere that details the syntax, or even mentions if it’s possible to utilize a view within that table for record creation via API.

To log a new score (using Postman to learn with), I have this;

https://api.airtable.com/v0/%My_Table%/HiScore?fields%5B%5D=Return&filterByFormula=(%7BStatus%7D%3D%22New%22)&maxRecords=3&pageSize=3&view=New

For readability;

HiScore
?fields%5B%5D=Return
&filterByFormula=({Status}=“New”)
&maxRecords=3
&pageSize=3
&view=New

With the JSON body data of;

{
  "records": [
    {
      "fields": {
        "Player": "Bazza",
        "House": "Red",
        "Score": 1000
      }
    }
  ],
  "typecast": true
}

Interestingly, I notice that it calls the View Name/ID where it’s stated on the API CodePen site “Only records in that view will be returned” - but confusingly, my experience is that I post a record and the details of that record (such as calc’d fields) are returned, regardless of the view specification. Regardless of if the record lands in the view, or the view has all fields hidden, the return is very complete;

{
    "records": [
        {
            "id": "recwln2xp65CbhqfS",
            "createdTime": "2022-07-02T21:42:05.000Z",
            "fields": {
                "Player": "Bazza",
                "House": "Red",
                "Score": 1000,
                "Return": "Bazza of House Red: 1000",
            }
        }
    ]
}

Further to the above return, if I create a record that is filtered OUT of that specified view, I’d expect my Post return to be empty (even though the record created). In short - I would expect Record recwln2xp65CbhqfS to only return if it had the filtered Status match.

Below shows the result of the newly created record - without the default Status “New” value I’m hoping to achieve. :cry:

I’m hoping this is possible, as it will mean much of my template data can reside within the Table itself under pre-configured views, meaning that data won’t have to be created and sent at the app level as JSON (which will be my first go-to workaround for this problem - as automating default values won’t provide the instant return).

Keen to read thoughts around this. I did search for past discussions but couldn’t find any that were talking about this in particular.

As a side note, thank you for this API tool; https://codepen.io/airtable/pen/MeXqOg I couldn’t have got this far without it.

No. It is not possible. When using the REST API, there is no context of an active view the way there is in the user interface.

The feature of having defaults set when creating in a filtered view only works in the user interface. Note that if you have records grouped only by editable fields, you also get the same effect.

If you create a record with the “+” in the lower left corner, note that the record is not created “in the view” and thus might be immediately filtered out and disappear as soon as the focus leaves the record.

This is the designed behavior, although it is not expected by some users. The visible fields in the view do not affect which fields are returned. The only aspect of the view that is used for REST API GET requests is the filtering.

2 Likes

This topic was solved and automatically closed 15 days after the last reply. New replies are no longer allowed.