Webhook to Create table AND copy records into new table

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • In Progress
Sorry if this is a n00b question but I can't seem to figure it out.  I want to create a webhook to Create a Table (figured that part out) and then add records to the new Table.  I don't know how to write an AddRecord webhook with the dbid of a Table that hasn't been created yet.  I don't think I can combine them into one webhook, but if I don't, I can't see how to prioritize the webhooks to ensure that the CreateTable happens before the AddRecord.  

Some context:
I have a master table of events that occur on varying frequencies (daily, monthly, quarterly, etc.).  I also have a table for generating new tables, where my user will select a Month & Year and click save.  The webhook is on this table and triggered when the record is saved.  So when the user selects August 2017 and clicks save, I want the webhook(s) to create a new table called August 2017 and copy all records from the Master Table that pertinent to August 2017 (daily=yes, monthly=yes, quarterly=no, etc.).  I've got lots of plans for helper fields to identify which are the correct records to copy/add, but I can't seem to get the basic Create-then-Copy flow figured out.  Can anyone suggest an approach or show me what I'm missing please?
Photo of Richard Pfister

Richard Pfister

  • 554 Points 500 badge 2x thumb
  • optimistic

Posted 1 year ago

  • 0
  • 1
Photo of Matthew Neil

Matthew Neil

  • 31,438 Points 20k badge 2x thumb
You are correct that you wont be able to add records to a table that doesn't have a dbid yet.

But you could guess what it should be.  If your table is going to be called August 2017, then the text version of the dbid would be [_AUGUST_2017]

The BIG question here is, why are you creating a new table for every month?  That does not sound like a good solution.
Photo of Richard Pfister

Richard Pfister

  • 554 Points 500 badge 2x thumb
Thanks for your response Matthew.
I didn't think about the text version of the name. If I could sequence the webhooks to ensure the table is created before trying to add records to it then I could use that.

The Why:
Every month certain tax filings are due.  We have to track the various stages of their completion with notes from the accountant processing them and prior months' details have to be preserved.  Some months include quarterly items or annual items so each month is not identical.  I can create a master table using generic references such as "3rd of the month" or "every 4th Tuesday", but the individual monthly tables will have the precise date and time ("July 15th, 8am") calculated from that table.  The master table can change from time to time with items added or removed, so it would be pointless to create all the monthly tables in advance, hence the user-input trigger.

I'm definitely open to the idea that I'm doing it the wrong/hard way (see profile pic) but in this case I don't know of a better approach regardless of technology being used.  Do you see another solution?  Thanks!
Photo of Michael Barrow

Michael Barrow

  • 2,206 Points 2k badge 2x thumb
I think you are definitely doing it the hard way. Have a single table and use one or more fields to code/categorize each time period/snapshot that you are trying to save. When you create a separate, new table each time, it's kind of the same effect as breaking normalization when designing a database. It seems like a good idea at the time, but the overhead and maintenance and extra crap you have to deal with whenever you program something to use the data is made harder each time, and managing all of those separate tables will become more than a chore.