Inserting multiple connected records simultaneously using record rules

As a Knack Builder, I would like multiple connected records to be inserted after a form submit so that all correct connected records can be inserted all at once rather than creating long workarounds.

Scenario: When a new class path is added, I would like enrollment records for all classes connected to that path to be created at the same time.

Has anyone gotten any further with this? I am trying to track capacity and want to be able to add a "task" in a joiner object for every sub service connected to a service that has been chosen in another object that is building the scope of work. I need to be able to track hours across the multiple tasks that may be associated with a single service (what shows on client invoice)

I have managed to get to the point where I can copy everything except for the connection field.

 

see https://support.knack.com/hc/en-us/community/posts/223976207-Update-connection-records 

Here is the code from the pre-built attendance app. I don't know javascript so it is all gobbly gook to me. I would love a way to adapt it to my own app. 

Basically, from what I can tell, this inserts a new "class attendance" for every "person" connected to the class when you create a new "class day."

var app_id = Knack.app.id;

var redirect = function (total, Class, attendance_Date) {if(total < 1) {Knack.hideSpinner(); window.location.replace('#classes3/classdetails/' + Class + '/classdaydetails/' + attendance_Date)} };

$(document).on('knack-record-create.view_149', function (event, view, record) {

  var user = Knack.getUserToken();

  var headers = { "Authorization": user, "X-Knack-Application-ID": app_id, "Content-Type":"application/json"}

  var attendance_Date = record.id;

  var Class = Knack.models['view_34'].toJSON().id;

  var Students = Knack.models['view_34'].toJSON().field_28_raw;

  var total = Students.length;

 

  Students.forEach(function (student) {

     

    Knack.showSpinner();

   

    var data = { field_72: attendance_Date, field_65: student.id };

    $.ajax({

      url: 'https://api.knackhq.com/v1/scenes/scene_72/views/view_145/records/',

      type: 'POST',

      headers: headers,

      data: JSON.stringify(data),

      success: function (response) {

        console.log('Attendance added!!!');

        total --;

        redirect(total, Class, attendance_Date);

      }

    });

  });

});

$(document).on('knack-record-create.view_141', function (event, view, record) {

 var Class = $('#view_141-field_71').val();

 var attendance_Date = record.id;

   var user = Knack.getUserToken();

 var headers = { "Authorization": user, "X-Knack-Application-ID": app_id, "Content-Type":"application/json"}

  $.ajax({

    url: 'https://api.knackhq.com/v1/scenes/scene_1/views/view_25/records/' + Class,

    type: 'GET',

    headers: headers,

    success: function (data) {

        Knack.showSpinner();

        var Students = data.field_28_raw;

        var total = Students.length;

     

     Students.forEach(function (student) {

      var data = { field_72: attendance_Date, field_31: Class, field_65: student.id };

         $.ajax({

           url: 'https://api.knackhq.com/v1/scenes/scene_72/views/view_145/records/',

             type: 'POST',

               headers: headers,

             data: JSON.stringify(data),

              success: function (response) {

     total--

              console.log('Attendance added!!!');

              redirect(total, Class, attendance_Date);

                }

         })

       });

    }

  });

});

$(document).on('knack-record-create.view_113', function (event, view, record) {

  var Class = Knack.models['view_92'].toJSON().id;

  var attendance_Date = record.id;

  var Students = Knack.models['view_92'].toJSON().field_28_raw;

  var total = Students.length;

 

  var user = Knack.getUserToken();

  var headers = { "Authorization": user, "X-Knack-Application-ID": app_id, "Content-Type":"application/json"}

 

  Students.forEach(function (student) {

    Knack.showSpinner();

    var data = { field_72: attendance_Date, field_65: student.id };

    $.ajax({

      url: 'https://api.knackhq.com/v1/scenes/scene_72/views/view_145/records/',

      type: 'POST',

      headers: headers,

      data: JSON.stringify(data),

      success: function (response) {

        console.log('Attendance added!!!');

        total--

        if(total < 1) {

          Knack.hideSpinner();

          window.location.replace('#classes/viewclassdetails/' + Class + '/classattendance/' + attendance_Date);

        }

      }

    });

  });

});

I need this function as well. Has anyone been able to accomplish it using javascript? The form rule would not work for me as it is unknown up to how many connected records I would need. 

YOu can do it through javascript. But I don't know how to do it. It exists in this form in Knack's pre-built attendance app, but does not make it very clear *how* to do it yourself. I guess you need to hire a javascript person. 

You're entitled to your opinions, but I thinks that's a little harsh.  Knack software is an integral part of my business and it makes sense that I should have to pay for it.  I think we are using the highest tier plan right now.  

In any case, do you think you can accomplish your goal by navigating to the form riles and using the record rules function?  I've been able to do some complicated things with just the basic knack functions without having to use the rules or API programming.


OK… I navigated the features and it looks like it would be possible to do this, but with additional payment.
You have to use “Tasks” and it’s only possible in Pro Plans.
I think that this is a basic feature that should be available to all.
I can understand that PRO plan gives you more disk space, more apps etc… but I think that all features of the software should be available to everybody who pays.
I suddenly have the feeling of being cheated with an unfair offer from knack.

 

It would be great to be able to populate connected records automatically.
I have an Event Object, a Members Object and an EventLog Object connected to both.
It would be great to be able to populate/insert connected records in EventLog Object (one record per member) connected to Event Object each time a new Event is created.
It would allow me to track members who did not confirmed attendance (default would be Pending answer) and then export members mail to ask them to answer.

 

Agreed, this would be helpful. 

Just wanted to add my +1 that this would be a fantastic feature.  

I can see what that would not be a great solution.  Do you want to talk about your application more?  Maybe there is a different way?

I don't think it can be done like Graeme wanted, but I think it can be done by another method.

Lets think of the example where you want to create records that connect a salesman to three clients.  

1) Make an object that has one field that is a connection to the salesman object (one to many), and then 3 connections to the client object (many to many) named client 1,2,&3.

2) Make a form where you can select the salesman and up to three clients.

3) Go to the record rules and add this rule.
Actiion: Insert a connecred record : a new (whatever record you are trying to create) connected to this record
When: Client 1 is not blank
Values: Set Salesman to a form value client 1

4) Then repeat the same rule three more times, except substitute client 1 with client 2, client 3, etc

Now, when a person submits the form, it will create the connected records.

There might be a more elegant way to go it using programming, or Zapier, but the above method is how you can do it with basic knack functions.  

So you want to create three records each connected to all three people, or do you want to create three records connected to one person?

If the former, then I've made it work by using the "record rules" of the form.  Basically I use a form to input all the data into one record, then I use submit rules to copy all of the data to a connected record.  You can also use the submit rules to insert multiple connected records.