Button that adds a variable amount of records to another table?

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered

Good afternoon!

I have the following problem: Table A contains Information on a certain action that should be preformed, the date the action starts, how frequently it needs to be preformed, and how many times it needs to be preformed. For each record, this information is different.

I want to populate Table B with all the dates on which this action should be preformed. The programmer in me says this problem screams for a for loop.

Right now I'm trying to use a button (URL field). However, I cant figure out how to use a for loop in that context. I tried to implement a code page, but I cant seem to figure out how to get the information from table A.

I know absolutely nothing of javascript and html, but I have a lot of experience working with java and c++.

Photo of elza


  • 0 Points

Posted 3 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
Code similar to what is in this pastie will add a variable number of child records:

Pastie Database

Since you didn't say what controls the the (1) starting date, (2) frequency or (3) number of iterations I just hardcoded some values in the script:

  var dateString = "2016-6-4";
  var n = 6;
  var daysToAdd = 7;

This set of parameters specifies six successive dates starting from June 4, 2016 spaced out by seven days.

These values will have to be (1) drawn from fields on the parent record or (2) perhaps entered through a popup dialog. You may have to enter additional logic to control the child record creation process (perhaps to only allow on batch of child record to be added) depending on your requirements.

While the code may look incomplete it is pretty much compatible with the code of 100s of other solutions I have provided. In other words, you may have to do a little more research to implement this solution as I don't repeat all the boilerplate and assumptions with each new question.

The only thing that is new in this solution is using the library moment.js and QuickBases AMD loader:

MomentJS Library


QuickBase uses the AMD loader library RequreJs and includes moment in the config so all you have to do is require moment to use it:

  require(["moment"], function(moment) {
    //your code here

It is actually pretty simple. Feel free to contact me if you need additional help setting this up.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
I am a bit tied up this week but I will top post a generic technique to this and related questions. Basically I will provide a generic example of placing a button on a parent table which when clicked will add a set of child records which will be initialized by (a) fields in the parent record, (b) through supplemental user inputs gathered through a popup dialog box, or (c) a combination of both. And to make in interesting I will make it a teachable moment to learn about the Category Theory concepts of catamorphisms (a fold), anamorphism (an unfold) and hylomorphisms (an unfold followed by a fold). The hard part will be coming up with a catchy name for the new technique.
Ohh Great.

Thanks Dan.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
See this Question and Answer which has a live demo:

What is the Hylo Technique?