How to Use Notion Button Variables to Edit Specific Database Items


Posted by Jo Lodge on 8 December 2024


Notion recently introduced a new feature: Variables in Buttons. This powerful update allows you to precisely edit specific items in a database - addressing a common issue in templates like my timesheet template. Previously, the limitations of the filter feature made it difficult to target the exact items you wanted to update.

With the new Variables feature, I’ve been able to enhance my timesheet template, enabling teams to track time across multiple tasks seamlessly. 

The Problem

Previously when using the "Edit pages in.." action in buttons you could only manually filter which items in the database you wanted to edit.

Like the "Stop" button in my timesheet example below, I could only get it to stop time on timesheet records where the end date was empty. This meant that any active timesheet was given an end time when you clicked the button. Limiting the template to only be used to track time on one task at a time.

undefined

The Fix: Using Variables

Now with the new variable function this can be fixed:

Edit the button

  • Edit the "Stop" button
  • Click on "Add Action" and select "Defines Variables"
  • Drag this action to the top of the list.
  • Name the variable e.g., theTimesheet (to make its purpose clear).  

Create the variable

  • Click the formula symbol to edit the variable
undefined
  • Add the following formula to the formula editor:
  • Select This Page to refer to the current task record where the button is located.
  • Use a dot (.) to access the page's properties and select the Timesheet property (the relation to the timesheet database).
  • Use .filter(current.End Date) to get all the related timesheets without an end date.

This page.Timesheet.filter(empty(current.End Date))

It should look like this 👇
undefined

Use the variable to add an end date

  • Delete the previous action that edited the end date
  • Add a new action: "Edit pages in.."
  • In the "Select database" drop-down select the theTimesheet variable you've just created. This means that you'll only update properties that the variable brings back.
undefined
  • In the edit properties section, choose End Date.
  • Set it to Time Triggered.
undefined

The result

Now when you click on the stop button it'll only add an end date to the timesheets related to the task and that do not have an end date.

this means you can record time against more than one tasks at a time.  Great if you're working in a team and all using the same tasks database.