Airtable’s Scripting block brings a new level of customization to your Airtable bases. The Scripting block will allow you to run scripts to enhance your bases and manage tedious tasks. You can do things such as create templates for records, prompt users, create custom reports, and much more. Once the script is added to your base, you can use it with the click of a button.
We are creating a library of scripts for you to use in your Airtable bases. We have many more examples on the way. These scripts will give you an even better understanding of the data in your base and eliminate repetitive data entry.
In this tutorial, we will show you how to set a default value for any record or field in your base.
With this script, every time you create a record in your base table, it will automatically add the data you set as a default. You will not have to manually enter the information. It will also add the data to records already created if you need to add or change previous records.
Setting a default value for a field will save hours of data entry and ensure data consistency, especially useful for records shared among multiple users. You can use this script for your entire table or you can choose a view to filter only specific records.
First, we will show you how to add the script to your Airtable base for the initial set up. This will only have to be done one time. We’ve created an easy template for you to start.
Second, we will show you how to use the script to configure and set your default values.
To use this script, you do not need to know any code or programming. You must have ‘Owner’ or ‘Creator’ permissions to set up the Script Block since you will be adding a table. You can then allow ‘Editor’ users to use the block.
If you would like the table to have a different name, you will need to change the name in the script. We will show you how to do this later.
This table is connected to the script to store all your defaults.
You now have fields with Name, Value, Type, Table, and Code. These correspond to fields in the first few lines of the script code we will add.
You now have the Script added to your base!
Or, you can also retrieve the code here.
Note: If you would like to change the Defaults table name or the field names, you will need to also change the names in the script.
Now, we will show you how to set default values for your fields. This is what you will need to do each time you need to add, change, or delete the default values.
All the tables in your base will now display. The tables in my base are Simple Table and All Fields.
The Defaults table you created earlier will not show since you don’t need to create defaults for your Defaults table.
You will then be given the option to choose a specific view. If you want to set defaults for only a specific view, choose the corresponding view. If you want to set defaults for all records in the table, choose No View.
Choosing a specific view is useful for updating default values for only a certain set of records. You may not want to update all your table records with defaults so choosing a view will allow you to specify which records need defaults. We recommend choosing a specific view if your table has a large amount of data.
Once you’ve chosen a View, all the fields from the table will be displayed.
Note: Currently, the cursor drops down to the last field. Scroll up to the top to start with the first field.
Each line will tell you the Field Name and also the Field Type. You can also see the current default value if you have already configured one.
To add a default:
Type your default value in the box and press Next. You can also hit Enter to save the current line.
If you do not want a default value:
Leave the box blank.
If you need to clear out a previously configured default value:
Press the spacebar and click Next.
Once you add all your default values, click Done.
It will now add your default values to the fields you set.
In this example, I set a default for the Notes field. The block will also tell you how many were updated.
To ensure each field displays your default data, review each of these field types to input your data with correct formatting. We have covered a majority of the fields. However, not every field type can have a default value set.
|Single line text||Text Data|
|Long Text||Text Data|
|Collaborator||Add the Collaborator’s email address|
|Attachment||This must be a URL to a publicly accessible file or image|
|Link to Table||In order to set defaults for linked records to other tables, you will need the Record ID from the record in the table where you want to link.
To obtain the Record ID:
Add a Formula field in the table you want to link. Type in RECORD_ID() then click Save. You will now have a Record ID for each record in the table.
|Single Link Record ID||Copy and paste the Record ID into the default value field|
|Multiple Linked Records Record IDs||Copy and paste the Record IDs into the default value field and add a comma between records|
|Single Select||Copy and paste the data from your Single Select field. These must be configured in your base prior to setting a default. You cannot add new single select options through the default value script.|
|Multiple Select||Copy and paste the data from your Multiple Select field. You can add more than one default from your Multiple Select field by adding a comma between multiple select options. These must be configured in your base prior to setting a default. You cannot add new multiple select options through the default value script.|
|Date||Format the date as MM/DD/YYYY. You can also add a Current timestamp by adding the word ‘now’ without the quotes.||
|Phone Number||Standard numerals|
|Standard email format|
|URL||Standard URL format|
Ex: 89 = $89.00 or your set currency
|Percent||Standard numerals in hundredths value
EX: Type .98 to get 98% or
.10 = 10%
|Rating||A numeral from 1 to 5
Ex: 3 = :star: :star: :star:
|Rich Text||Currently Not Supported By Scripts Block…||Coming Soon…|
You can now set defaults for fields in your base. All you need to do is click Configure Defaults when you need to change or update them.
If you have any trouble, join our Slack community and we will do our best to help you.
We are adding more scripts all the time so join our community to get the latest.
BuiltOnAir is the ultimate resource for all things Airtable.
Sorry, your idea is very useful indeed, but it’s too difficult to get it working, very fragile.
This is my second attempt: what did I wrong?
ERROR: UserInputStartTime and some lines following, but after 10 mìnutes I’m trying to upload, copy, link the error message and I always get the anser “not possible in a post” I don’t know how to send you
Running, Configuring Defaults defaults, and then hitting Done will result into this. No changes has been made:
at Object.setIsAwaitingInput (h ttps://cdn.airtableblocks.com/bbndrri8ECnp9OEHg/bundle.js:1:3046605)
at _callee2$ (h ttps://cdn.airtableblocks.com/bbndrri8ECnp9OEHg/bundle.js:1:2960935)
at tryCatch (h ttps://cdn.airtableblocks.com/bbndrri8ECnp9OEHg/bundle.js:1:1597474)
at Generator.invoke [as _invoke] (h ttps://cdn.airtableblocks.com/bbndrri8ECnp9OEHg/bundle.js:1:1597079)
at Generator.prototype. [as next] (h ttps://cdn.airtableblocks.com/bbndrri8ECnp9OEHg/bundle.js:1:1598372)
at asyncGeneratorStep (h ttps://cdn.airtableblocks.com/bbndrri8ECnp9OEHg/bundle.js:1:2958700)
at _next (h ttps://cdn.adfsdfirtableblocks.com/bbndrri8ECnp9OEHg/bundle.js:1:2959001)
ps. sorry I had to add a space between “h” and “ttps” so that it won’t read as a link. According to Airtable new users can only post 3 links