Access Rules: Restrict creation of new record until all mandatory fields are filled in

You can use Access Rules to restrict a user from creating new records until all mandatory fields are filled in for existing records in a table.

Example Document: ACCESS RULES - Restrict Row Creation - Grist

In this example, we have three columns in our Contacts table; Name, Phone and Email.

First, we need to add a column that checks if all mandatory fields are filled in. We can add a new column, Row Complete? with the following formula:

bool($Name and $Phone and $Email)

This formula uses Python’s bool() to return a boolean value (True or False) if $Name, $Phone and $Email exist for this record.

Add another column, Access Rule, with the following formula:

Contacts.lookupOne(Row_Complete_=False)==rec

This formula uses lookupOne to find the first record in the Contacts table where the value in the Row Complete? column is False. Then, if the record found in the lookupOne formula is the same as this row, it returns True. Only one row will ever be True. All others will be False.

We’ll use this column in setting up our Access Rules.

Navigate to Access Rules by clicking the Access Rules link under the Tools menu of the left-hand navigation panel.

Under ‘Add Table Rules’, select the table where you want to restrict Create access. For this example, we want to restrict record creation in our Contacts table when mandatory data is missing from existing records.

Add the condition not rec.Access_Rule and restrict the Create permission.

Be sure to leave a memo for the condition so users understand why they are receiving an error.

Click the green ‘Save’ button at the top of the page to save your changes.

Now, if you attempt to add a new record to the table before all mandatory fields are filled in for existing records, you’ll receive the error.

HOW THIS WORKS:
The formula in the Access Rule column is written so that only one row will be True and all others will be False. The row that is True is the only one that can be “created”. For example, when you start with an empty table, the “Add New” row will have True in the Access Rule column which means the condition not rec.Access_Rule will be false since it is inverting the value with not and the rule won’t apply, allowing you to create your first record. Once the record is created, the value in the Access Rule column will be True which means all others, including the “Add New” row, will be False. Our Access Rules condition will invert this to True, which will cause the rule to be applied and prevent you from creating another record. The only way you can create a new record is by filling out all of the required fields in the last record, changing the value in Access Rule to False and making the value for the “Add New” row True.

3 Likes

Hello, I tried your hint on how to restrict creation of new record until all mandatory fields are filled in for existing records in a table. It works with Text and number fields. But it doesn’t seem to work with a text and reference or choice field. In this case, even if all mandatory fields are filled in all records, when I try to create a new one, it blocks the creation. Is there a workaround or did I do something wrong?

Hi Alfredo,

It should still work regardless of column type. I added a reference column and choice column to the example.

https://public.getgrist.com/x12hvsA9bg1W/ACCESS-RULES-Restrict-Row-Creation/m/fork

When any fields are empty, you still get the error saying you cannot create a new record prior to filling in all values

Once all fields are filled in, Row Complete? becomes true and you’re able to create a new row.

Note that Row Complete? needs to be updated to include all columns in its bool() formula.

Please feel free to share your document with support@getgrist.com and I can take a closer look to see what the issue might be.

Thanks,
Natalie

Thank you. Probably I did something wrong. I applied the rules again and it is working. I’ll do other tests and in case I get stuck I’ll share my documento with you.
Regards

1 Like

I know Grist is a small team, but it would be really nice if some the acess rules stuff was more automated. Like instead of creating such column with formula and adding access rule, each column just had a REQUIRED? checkbox.

It would simply create that column in a hidden way (system column?) and add extra fields in the formula for each “required” checked column.

The access rule could also exist “in system”. If the user selects required columns, it will automatically work, if there is no required column, this hidden access rule will simply not be used.

2 Likes