Duplicating a row with its relationships

Hello :smiley:,
I’m wondering if we can “Duplicate current row with its relationships” ?
If I duplicate one Catalog, I want also duplicate each Page related to it.


Hi @Sao. That’s an interesting idea.

Grist doesn’t support it today, but you could construct such functionality for a particular table with the ActionButton custom widget. A somewhat similar application was a topic in a webinar here: Build with Grist Webinar - Custom Widgets - Apr 14, 2022 - YouTube, and the usage of ActionButton is described in this post (there is a link to an example there).

For a general feature, duplicating related records isn’t always appropriate. E.g. a line in a shopping cart would have a reference to some Product. But since it’s not a part of the product, it wouldn’t make sense to duplicate it if one were duplicating the product. In other words, the user would need to choose which relationships are included into the duplication.

It would be cool if Grist had a concept of “ownership”, i.e. whether a Page is “owned” by the Catalog it refers to. That could mean that duplicating a catalog would duplicate its owned pages, and deleting a catalog would delete its owned pages.


I tried but without success :sweat_smile:.
How can I list all attributes of the class Catalog, without enumerating them manually one by one.
So if I add a new row, it will be automatically in the list to duplicate.
I tried “Catalog.dict”, “dir(Catalog)” … but I couldn’t find the attribute’s names
And my second question is :
How to duplicate first the catalog itself and then the pages with the ID of the catalog I just duplicate, because there is no return value with the first action, is there any ?
Or I should use instead the API to do it ?

pages_count = len(Pages.lookupRecords(catalog=$id))
  "button": "Duplicate catalog {} ".format($title),
  "description": 'Duplicate the catalog "{}" with his {} pages'.format($title, pages_count),
  "actions": [["AddRecord", "Catalog", None, {
      "title": $title,
      "data": $date,
       .... : ...
    }], ],