Can you use a single webhook to create multiple records in a child table

  • 1
  • 1
  • Question
  • Updated 11 months ago
  • In Progress
I have a series of 14 check boxes, each representing an equipment type. I have a child table of Equipment Schedules under the parent Projects. What I am trying to accomplish is simply checking the boxes for the equipment needed on a project, save and have the enter a single line item for each piece of equipment. I have tried this with Actions and it works but the problem is I have to have 14 individual actions. I also need to relate the project, project type (New Store or Remodel) and enter the equipment description based on the checkbox name.

I am wanting to do this instead of Add New Equipment multiple times.
Photo of Joey Zint

Joey Zint

  • 1,508 Points 1k badge 2x thumb

Posted 11 months ago

  • 1
  • 1
Photo of Evan Martinez

Evan Martinez, Community Manager

  • 8,774 Points 5k badge 2x thumb
Hi Joey,

For what you are looking to do with your Webhooks you would most likely want to make use of the API Import from CSV. It can be formatted using the %repeaton% %repeatoff% and field markers to create a set of records. Here is an example below:

<qdbapi>
<usertoken>InsertUserTokenHere</usertoken>
<apptoken>app_token</apptoken>
<records_csv>
%RepeatOn%
  <![CDATA[
"[Date Created]","[Project Name]","[CheckBox1]", "[Record ID#]","First Record Created by Webhook" 

"[Date Created]","[Project Name]","[CheckBox2]", "[Record ID#]","Second Record Created By Webhook" 

"[Date Created]","[Project Name]","[CheckBox3]", "[Record ID#]","Third Record Created By Webhook" 

"[Date Created]","[Project Name]","[CheckBox4]", "[Record ID#]","Fourth Record Created By Webhook" 

"[Date Created]","[Project Name]","[CheckBox5]", "[Record ID#]"," Fifth Record Created By Webhook" 
 ]]>
%RepeatOff%
</records_csv>
<clist>6.7.8.9.10</clist>
<skipfirst>0</skipfirst>
</qdbapi>

This is just a rough example, but essentially it is using the one record creation to trigger off a set of Records being created using the Import from CSV function in a Webhook. Each line would just be another record created in the endpoint table. This is just an example off the top of my head so it would need some refining for your use case but I think it is the right direction for what you are looking for. I hope this suggestion is helpful Joey. I have also linked below the Import from CSV help document that goes over the syntax for building an API Import from CSV.

http://help.quickbase.com/api-guide/importfromcsv.html
Photo of Joey Zint

Joey Zint

  • 1,508 Points 1k badge 2x thumb
Here is what I have so far. I am using the rule of when any of the checkboxes change, then fire the webhook. Do I need to have that part of it setup as well



Photo of Evan Martinez

Evan Martinez, Community Manager

  • 8,774 Points 5k badge 2x thumb
You would want to include your actual trigger conditions for the webhook, as my example didn't have any triggers or endpoints in place. Looking at your current set up that would create one record in the end point table from one record being added. what you just need to do is for each record being created it needs to be broken out into its own line without a comma like below:

"[Date Created]","[Project Name]","[CheckBox1]", "[Record ID#]","First Record Created by Webhook" 

"[Date Created]","[Project Name]","[CheckBox2]", "[Record ID#]","Second Record Created By Webhook" 

"[Date Created]","[Project Name]","[CheckBox3]", "[Record ID#]","Third Record Created By Webhook" 

"[Date Created]","[Project Name]","[CheckBox4]", "[Record ID#]","Fourth Record Created By Webhook" 

"[Date Created]","[Project Name]","[CheckBox5]", "[Record ID#]"," Fifth Record Created By Webhook" 

What it then does is it reads each line like a line in a CSV file, with the commas telling it the break between each field. So this example would create 5 records containing the 5 pieces of information in each line of text without a comma at the end and then each lines goes into the fields in the destination table indicated in the clist at the bottom, in the order indicated.  So in my example

<clist>6.7.8.9.10</clist>

Date Created goes into field 6, Project Name goes into field 7, Checkbox1 goes into field 8, etc. Then when it has gone through all 5 fields and it reaches that next line it starts over at field 6 again. 
Photo of Joey Zint

Joey Zint

  • 1,508 Points 1k badge 2x thumb
Here is what I have now.....

As you can see, I only checked three boxes yet it made 14 entries and loaded the condition of the checkbox (yes or no) where that needs to input the name of the checkbox

Photo of Evan Martinez

Evan Martinez, Community Manager

  • 8,774 Points 5k badge 2x thumb
I see the issue here Joey and that is going to be more complicated within the webhook formatting. It is always going to create all of the records listed specifically in the webhook, as is it won't just conditionally fire that webhook for each checkbox that happens to be checked. It will always create those 14 records in that template.

Using field tags doesn't call the fields name it calls the value stored in that field (in this instance the yes or no) you would instead need to write in the Text you wanted to call for that fields name as plain text inside of quotations. For example

"[Record ID#]", "[Project Type]", "Name of Field without Field Markers here"

For what you need that is going to require a more complex webhook that builds in some custom queries to limit the data return, or it is going to require a separate webhook or action for each condition you want to check against before creating a record. The complex webhook with queries built in to control the output goes outside of my expertise unfortunately. It is possible someone else on the forum might be able to chime in with how they are doing something similar or a Partner more experienced with more robust webhooks could help to design something for you.
(Edited)
Photo of Joey Zint

Joey Zint

  • 1,508 Points 1k badge 2x thumb
Thank you for the quick response, I will keep plugging along. At least I am getting it to somewhat work
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
Joey,

I have been in this situation before.  One solution is to create a formula field to calculate the related parent, and if the checkbox was not checked then you will create the child, but deliberately make it an orphan.  ie se Related Parent to zero.

Then from time to time say each month subscribe to a report of orphans and delete then.

or you can even fire a webhook to delete all orphans.

So always create the full set of children, but to the user, they will only see the ones which are properly connected to the Parent record.
Photo of Joey Zint

Joey Zint

  • 1,508 Points 1k badge 2x thumb
Can you write if statements into each line to test for the checkbox like this

If([(CU) Condensing Unit],("[Record ID#]","[Project Type]","(CU) Condensing Unit","")
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
You cannot write formulas in the webhook box itself, but create 14 fields in your app to calculate either to [Record ID#] or zero.

In your webhook you now refer to the field [Record ID#] in each line.  Replace that with 14 fields such as

[Record ID# or zero if Not CU]
[Record ID# or zero if Not another type of checkbox #2]
etc
[Record ID# or zero if Not another type of checkbox #14]
Photo of Joey Zint

Joey Zint

  • 1,508 Points 1k badge 2x thumb
So the record ID is the ID of the project. The equipment table is a one to many relationship of the project.

I think I get it. I will give it a try
Photo of Jason

Jason

  • 1,012 Points 1k badge 2x thumb
You could create a formula text button that could use the api_editrecord to check the box on that record and also use the api_addrecord to add a record with the information you need to the other table. You could even go a bit further and make the button uncheck the box and delete the record. It is a bit complicated at first but easier to master than you think. If you can webhook you can learn this.
 If this is an avenue you want to pursue send me an email. I will give you examples and be able to answer questions.
 
Photo of Joey Zint

Joey Zint

  • 1,508 Points 1k badge 2x thumb
Thanks Mark....this worked but as you stated it does put junk in my Equipment Schedule table. I will have to created a webhook or action to delete those....it will fill up pretty fast


Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,436 Points 50k badge 2x thumb
You should be able to fire a webhook to purge all records where the [related parent] = 0.  You can make a report with that filter and then the API_Purge has a parameter to set the report to follow for the purge.  Be sure to hide that report to no one changes the purge parameters.

Or you may be able to make that report and then use the "more" button to get at the code which defines the purge parameters and build that into your Webhook.  That would be safer.