Action Button Info

Hey all!

Anyone have additional info on using the custom widget template “Action Button”? I haven’t been able to find much info on how to use it, and don’t fully understand the syntax of the formula(s) used.

I’m hoping to be able to be able to use it to duplicate a record X number of times, so I’d be especially thankful for any tips on setting the button to do multiple actions/a single action multiple times!

Thanks in advance :slight_smile:

Apologies, it is indeed utterly undocumented. It exists as a workaround; hopefully we’ll have a better solution before long. The Action Button needs access to a column, with a formula that returns a value of this form:

{
    "description": "Some description text",
    "button": "Text of the button itself",
    "actions": [ACTIONS_TO_APPLY],
}

The actions field is a list of actions, having this form (for the most common kinds):

[
  ["AddRecord", "TableId", None, {"Col1": Value1, "Col2": Value2, ...}],
  ["UpdateRecord", "TableId", rowId, {"Col1": Value1, "Col2": Value2, ...}],
  ["RemoveRecord", "TableId", rowId],
]

The "actions" field should be a list of actions, and each action itself has the form of a list. So a single AddRecord action would look like [['AddRecord', 'MyTable', None, {"ColA": "ValueA"}]] (with two pairs of brackets).

There is an example of an Action Button to duplicate rows here: https://public.getgrist.com/ubYNJ1PPN9Vn/Action-Button/m/fork; it was used for a recent webinar.

2 Likes

Awesome, thanks!

Is there a way to make this work with reference columns? When I use the action button to duplicate a record, the new records have errors in reference columns (I just used “ReferenceColumn”: $ReferenceColumn in the action code)

Ah yes, $ReferenceColumn attempts to give you a useful object (e.g. to enable $Ref.Field notation), but for these actions you need the underlying numeric identifier. Try replacing $ReferenceColumn with either

int($ReferenceColumn)

or

$ReferenceColumn.id

Either one should fix it.

1 Like