Help

Re: Script: Set Defaults

9291 0
cancel
Showing results for 
Search instead for 
Did you mean: 
openside
10 - Mercury
10 - Mercury

Introducing Default Field Values via new Scripting Block

Brought to you by the team at BuiltOnAir & Openside/On2Air

Overview

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.

717070e4c19b40b08ef38dc45d81553028e0a27a.png

About This Script: Setting Default Values

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.

Example Base & Script

Install from the Universe this Block

OR

How To Set Up the Scripting Block for Setting Defaults

1. Create a new table in your base and call it Defaults

797d6ac2aa72aec35eebee304224bf53b1cc6090.png

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.

2. Copy all records from our example base and paste into your base in the Defaults Table you created

0e52d08464242aeca7ad64b43a2a082fa944040a.gif

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.

3. Click the Blocks button in the top right corner

a89ce72262c5c95785b010d5d49c1ec240f991ac.png

4. Click Add a block and choose the Scripting block

3555232e0baa9ffc2926217a176cccbbdc603a27.png

fc1f2d77a185f635b1175a964aa7d20de2f0e03e.png

5. Click Edit in the top right corner of the block to open up the script editor

5ae895fb178301fe5afbd6cfb79ec0ccaf0e139f.png

d9dfa678f15da2e56d2cd8e4ebe95fc98c9ec95c.png

6. Copy the script from our example base and paste it into your script editor in the top left box

2122e89c1a169fc0e2de92f4f6bf9f9d7e91e319.png

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.

13cbd5df304ab616edf7a4c1032bc7d089cfb2f1.png

How to Add Default Values

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.

1. Click Run

8518e5d7ed1a43666517ea5530c7bad45e470014.png

2. Click Configure Defaults

8dedc65f71f81e481a9572b58fd560ad7bfdc96f.png

All the tables in your base will now display. The tables in my base are Simple Table and All Fields.

c19bd7be76218cfbd57771739f3be115d395bdde.png

The Defaults table you created earlier will not show since you don’t need to create defaults for your Defaults table.

3. Select the table and view where you want the default values set

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.

087043520875bdd122a272f41db3a77bf5960a5b.png

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.

3a80e8708d0ca2c20858ddba29012371ef93f734.png

4. Set your defaults

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.

6c6cbb04af5a7def700c6ca6d8e0bd53b7fb9d26.png

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.

5. Click Set Defaults then choose the table where you added Defaults

87b49ef6d1ef3ae0fa0e89e81058bfdfcdcf8505.png

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.

eac0b4ed7ebecceed5e1339892b59d6588e01662.gif

Defaults By Field Type

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.

FIELD TYPE FORMATTING EXAMPLE
Single line text Text Data c8fcddc2c3274ea58e57579ded61ab7cb4008eb9.png
Long Text Text Data af2e2ed7510d42f35fa1200bfffbd28bee786f0d.png
Collaborator Add the Collaborator’s email address 8ac0be7fe4ede2a35bbcb76a5b555804fbad6873.png
Attachment This must be a URL to a publicly accessible file or image 2b7de202a2c615c355f5348d949f02c4feb803e0.png
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.
Formula:
27ce2010d0f5baf87e14a95de0f1fbc44b5fc7ae.pngRecord ID:
0b63b993754a2bca224976f73330433be9de3d5f.png
Single Link Record ID Copy and paste the Record ID into the default value field 5d85441f8380d03bf952a848bf888dfbbde39c3e.png
Multiple Linked Records Record IDs Copy and paste the Record IDs into the default value field and add a comma between records b2ca86ecbe1fab15cb0b18ed7047bdd06e7067cc.png
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. 52f0f7fc59bda8ea14e3c6a0d5c2bf6c7c5933de.png
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. 9f386c654695b8d60d73680527c4e5e95730053b.png
Date Format the date as MM/DD/YYYY. You can also add a Current timestamp by adding the word ‘now’ without the quotes. ab4ead7a840d844ce8168629f9fdfbfb3b839618.png
d348808c12d4af402f4d8783d503f99277ca1a45.png
Phone Number Standard numerals 21dfa130e94b946e380b3a980f9f8bf2603938c5.png
Email Standard email format 9af88444716588b07d4de105dfbf9f4c98da57e0.png
URL Standard URL format 4d9a93940548cfc1809c2bf18d18101149877a02.png
Number Standard numerals d1eecfefee5132066489d912c8e939c421d648cc.png
Currency Standard numerals
Ex: 89 = $89.00 or your set currency
32d6741b59ef7a0e94c40d832a9d36a01b8d187e.png
Percent Standard numerals in hundredths value
EX: Type .98 to get 98% or
.10 = 10%
a69d3d472251e3e56edb88bfc727c07a43064268.png
Rating A numeral from 1 to 5
Ex: 3 = :star: :star: :star:
af8aefc0f029cd9d3cf8329b593c731b33e7e33c.png
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.

Stay Updated

5ecafa198d9de864b9802848d39380cfcd61ec48.png

BuiltOnAir is the ultimate resource for all things Airtable.

Utilizing the new scripting block, we can now address several product suggestions:

7 Replies 7
Leonardo_Felici
5 - Automation Enthusiast
5 - Automation Enthusiast

What should I do? I simply copied the full base and run. But I get an error:

TypeError: input.buttons is not a function
at start on line 211
at main on line 367

Thanks
LF

Did you get the script from the Airtable universe? This thread about breaking changes explains why you are getting that error.

You can find a fixed version of the script on the Built on Air website.

openside
10 - Mercury
10 - Mercury

Hi @Leonardo_Felician - thanks for bring that up. I re-published the base with updated scripts. You can re-copy and it should work. Or also like @kuovonne mentioned you can copy the script from BuiltOnAir.

Leonardo_Felici
5 - Automation Enthusiast
5 - Automation Enthusiast

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

Operations_Kaho
5 - Automation Enthusiast
5 - Automation Enthusiast

Running, Configuring Defaults defaults, and then hitting Done will result into this. No changes has been made:

ERROR
Error: userInputStartTime
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

openside
10 - Mercury
10 - Mercury

hmm, it appears some recent changes to the scripting block api are causing this error. i’ll have to revisit it when I get some time.

Ujjwal_sukheja
4 - Data Explorer
4 - Data Explorer

It is showing the same error when I’m hitting done while configuring the default values.

Error:
N: userInputStartTime
at start on line 352
at async main on line 367

Did anyone got the solution for this?