Using template tables to copy new rows into second table

I have a relatively simple Project table and Task table. I was able to set up a button on the project table so that when the “category” (select field) is set to “Webinar” the button becomes active and when executed, copies all rows from a webinar template table into the task table. My problem is that I am having trouble expanding on this so that the code works for multiple categories. For example, if the Category is “Event” the tasks copied would either come from a separate template table, or from one giant template table (but only copy those where the category matches). My code for the webinar tasks button looks like this (the modifyrow command is used to deactivate the button once tasks are copied for the given project):

RunActions(modifyrows(thisRow,[Marketing Projects].[Tasks created],true), Foreach([Webinar Task Template],AddRow(Tasks ,Tasks.[Project ID] ,thisRow.ID,Tasks.[Project Description],thisRow.[Project Description],Tasks.Task,Currentvalue.Task,Tasks.Owner,currentvalue.Owner , Tasks.[Due Date],thisRow.[Due Date]-Currentvalue.[Days prior to Due Date],Tasks.[Task Status],“Not Started”,Tasks.Duration,CurrentValue.[Duration (Days)])))

Using an IF clause, I attempted to duplicate this code for addditional categories, however it will not recognize “current” value beyond the first “AddRow” section. I am looking for a way to either 1) have the code copy only those tasks for which Category=x, or 2) copy rows from different tables depending on the category in the project table. Any ideas? Thank you!

Hi @Wendy_Levine :blush: !

How about using SwitchIf() to indicate what to do if Category = x, Category = y, Category = z …

Something like (see the sample below… even though I know this won’t reproduce your setup) :

RunActions(
SwitchIf(
  thisRow.[Column 2] = [Category 1],
  ModifyRows(thisRow, thisRow.[Column 4], Concatenate("A")),
  thisRow.[Column 2] = [Category 2],
  ModifyRows(thisRow, thisRow.[Column 4], Concatenate("B")),
  thisRow.[Column 2] = [Category 3],
  ModifyRows(thisRow, thisRow.[Column 4], Concatenate("C"))
 )
)

So, if the category in thisRow.[Column 2] is [Category 1], the button will modify the row and Concatenate("A") in thisRow.[Column 4], for [Category 2] it will Concatenate("B"), etc …

I don’t know if it might be something you could try (don’t hesitate to share a sample doc, so we could take a look :blush: ) but it’s just an idea :blush:

Thank you for your reply! I think this leaves me with the same problem, however. I’m new to using this forum, so please let me know if you are able to see my sample doc here. The last row of of the Marketing Projects table (Projects page) has an active button in the last column that copies all rows from the Webinar Task Template table to the Tasks table. This is enabled when Category=Webinar. I’d like to duplicate this functionality for a couple of other Categories and am unsure of the best way to do this (short of creating a separate button for each Category). See my info on my initial attempts above. Thank you for any input!

Hi @Wendy_Levine :blush: !

So, I’ve quickly added a button to your sample doc (thanks for sharing :raised_hands: ) implementing the SwitchIf() :blush: (See Auto create tasks - 2)

Now, to test this, I’ve just copied/pasted the same series of actions for the case where Category = Webinar and Category = Website as I didn’t know what supposed to happen exactly if the Category in this row was Website :blush: (in case the actions would need to be different)

If you need to run the exact same set of actions for multiple categories you could also use something like (See Auto create tasks - 3) :

RunActions(
  SwitchIf(
    thisRow.Category = Webinar OR thisRow.Category = Website ,
      RunActions(
        A set of actions
      )
   ),
  thisRow.Category = [Paid Campaign],
    RunActions(
    Another set of actions
    ),
 thisRow.Category = [Another Category],
  RunActions(
     yet another different set of actions
    ),
Etc ...
  )
 )
)

The Disable if formula would also need adapted :blush:

Note that to select the different categories in the buttons, I’ve @ref directly the specific row stored in your table Category :blush: (which can be done by typing @ + at least the 2 first letters of a category in the Editor, Coda will make some suggestions regarding the row(s) you can use).

It’s a shortcut to :

Category.Filter(CurrentValue.Category = thisRow.Category).First() 

Let me know if this helps :innocent:

Add-on (:innocent: ) : Regarding what should be done and how it should be done if a Category is for example, Website in “a templated way” , I don’t think there’s really a right or wrong way to do this :blush:

You could perfectly use different tables (1 per category) and change the table to use in your ForEach() for the appropriate category or a big one where each task would be linked to a specific category and use something like this in your Button Formula :

[Task Template].Filter(CurrentValue.Category = Website).ForEach(
  AddRow(
  ...
 )

I’ve just updated the button [Auto create tasks - 2] which now uses the table [Task Template 2] to create the various tasks depending on the Category :blush:

Hope this helps :innocent:

1 Like

That was the help I needed. Thank you very much!

1 Like

A bit late but : No problem :wink: !

Always glad to help when I can :blush:


For the sake of completeness and just in case someone else would like to do something similar, here’s a sample somewhat reproducing the desired workflow :blush:

The purpose of the button in the original post was to add “templated rows” to a table depending on the category selected in thisRow, add or manipulated certain values to the brand new rows and mark a checkbox as checked when the button has been pushed (so the button could be disabled)

As this could be done in various ways (depending on the final expected result and the action to perform), I’ve decided to illustrate 3 of those using 3 different buttons :blush: … But principles behind that workflow stay the same …

So, in the sample there’s a table storing the different categories, a table storing the “templated rows” where each row has been linked to a specific category, a table called [Add Rows Here] where the templated rows are added (also linked to the table Categories) and the table Test where each row has also be linked to a specific category and where the buttons are :blush:

  • 1st Button ([Add Templated Rows 1]) : Adds a certain quantity of “templated rows” to the table [Add Rows Here] depending on the category selected in thisRow.Category and do somewhat 3 different actions (to some extend) if thisRow.Category = [Category 1], thisRow.Category = [Category 2] or thisRow.Category = [Category 3] … Then, it checks the checkbox [Is Clicked]

  • 2nd Button ([Add Templated Rows 2]) : Adds a certain quantity of “templated rows” to the table [Add Rows Here] depending on the category selected in thisRow.Category but will do the exaction same thing regardless of the category … Then, it checks the checkbox [Is Clicked 2]

  • 3rd Button ([Add Templated Rows 3]) : Works similarly as the 1st button but the action formula is written differently :blush: … Then, it checks the checkbox [Is Clicked 3]

(The different Action formulas are visible in the sample, below the [Add Rows Here] table )

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