Automatically Duplicating Items with Sub-Items

Hi everyone!

Has anyone found a way to use a button or an automation to duplicate an item with a subitem(s) and have that relationship maintain properly (meaning the new subitem is connected to the new parent item).

I have a task board for my team for onboarding based on an SOP. Our HR person has 65 tasks with some subitems. What I am trying to do is make it to when there is a new person added to our onboarding board, her tasks get added automatically by duplicating or adding the templated tasks.

I’ve tried duplicating the tasks through automation and buttons, with loads of different formulas, but the subitems either connect to the old parent, don’t connect at all, or the formula just won’t work. I’ve also tried having a template table and trying to copy them over the the new one. I’ve tried having a TmpParent column and matching afterwards. I can never get it to work.

I would prefer to duplicate is because some rows have a button in a canvas column that is unique to that row and I don’t think I could add that using an automation or button that added rows rather than duplicated them

I feel like there has to be a way and I’m just missing it because you can easily right click the parent, press duplicate and it duplicates the parent and children correctly. We could use this of course, but it leaves a lot open to error and we would much prefer something automated.

1 Like

Hello @Samantha_Korth ,

Yes, with a bit of extra effort, you can do exactly that. It is a bit hard to explain how to do it in the community, so I made a small sample doc that hopefully explains itself.

I hope this helps.

Greetings,
Joost

4 Likes

For a non-recursive solution (only a depth of 1 direct subitem level), which is what it seems you might be after anyway, I found a pretty clean solution

thisRow.Subitems
  .DuplicateRows(
    thisTable.Parent, thisRow.DuplicateRows()
  )
3 Likes

I edited my button formula: when I was setting this up, I had used a containstext() function, but that can in some special situations lead to errors, so I changed the formula to contains() and I used ‘object’ rather than ‘name’ for the comparison, which is more precise.

The solution from @Rickard_Abraham is a nice demonstration of clean CFL, but I don’t like (for this particular use case) the row button - the canvas button allows for some extras.

4 Likes

Appreciate the responses! Using @joost_Mineur ’s solution as a base, I managed to use a formula button to make it work with up to 3 levels of subitems! What I was trying to do is have a parent table for the onboarding record ie. the person we are onboarding (Onboarding Employees) then an onboarding task table (Onboarding Tasks) and have the button be on the parent table. The button would find everything that had a template status and was HR department and duplicated those. I also needed it to not rely on unique names for the tasks because they are templated and therefore wouldn’t be unique. It took me a while but I managed to do it! Thanks for all the help!

So my task table is like below, with a relation column to the onboarding record table which is the name of the person we are onboarding. I then have a department select and a template status select:
Task A

Task A.1

Task A. 1. 1
Task B

Here is the formula for the button - reminder this is on the parent table and activated from there:

RunActions(
  [Onboarding Tasks].Filter(Parent.IsBlank() AND [Template Status] = "Template" AND Department = "HR").FormulaMap(
    DuplicateRows(
      CurrentValue,
      [Onboarded Employee], thisRow,
      [Template Status], ""
    )
  ),
  [Onboarding Tasks].Filter(Parent.IsBlank() AND [Onboarded Employee] = thisRow AND [Template Status].IsBlank() AND Department = "HR").FormulaMap(
    WithName(
      CurrentValue,
      NewParent,
      WithName(
        [Onboarding Tasks].Filter(Parent.Name = NewParent.Name AND [Template Status] = "Template" AND Department = "HR"),
        TemplateLevel1Subitems,
        RunActions(
          TemplateLevel1Subitems.FormulaMap(
            DuplicateRows(
              CurrentValue,
              Parent, NewParent,
              [Onboarded Employee], thisRow,
              [Template Status], ""
            )
          ),
          TemplateLevel1Subitems.FormulaMap(
            WithName(
              CurrentValue,
              TemplateLevel1Subitem,
              WithName(
                [Onboarding Tasks].Filter(Parent.Contains(TemplateLevel1Subitem)),
                TemplateLevel2Subitems,
                TemplateLevel2Subitems.FormulaMap(
                  WithName(
                    CurrentValue,
                    TemplateLevel2Subitem,
                    WithName(
                      DuplicateRows(
                        TemplateLevel2Subitem,
                        Parent, [Onboarding Tasks].Filter([Onboarded Employee] = thisRow AND Parent.Contains(NewParent) AND Name = TemplateLevel1Subitem.Name).First(),
                        [Onboarded Employee], thisRow,
                        [Template Status], ""
                      ),
                      NewLevel2Subitem,
                      DuplicateRows(
                        [Onboarding Tasks].Filter(Parent.Contains(TemplateLevel2Subitem)),
                        [Onboarding Tasks].Parent, NewLevel2Subitem,
                        [Onboarding Tasks].[Onboarded Employee], thisRow,
                        [Onboarding Tasks].[Template Status], ""
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  )
)
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.