Hi Brad,
I got the insert part to work. I'm struggling, however with the part where I assign values to the target object from the checked table records in the data variable:
// Define the fields you want to update
var data = {
field_741: record_ids.field_283,
field_762: [record_ids.id],
field_751: record_ids.field_276,
field_751: [record_ids.id],
field_763: BuyerName,
};
I have copied my code here. Maybe you can see where I;m going wrong?
Thanks for the help.
Dagmar
var insertRecords = function(id, record_ids, data) {
$.ajax({
url: ‘https://api.knackhq.com/v1/objects/object_32/records’,// + id,
type: ‘POST’,
/***** CHANGE TO YOUR OWN APPID AND API KEY HERE *****/
headers: {‘X-Knack-Application-ID’: ‘578773182826ba663f18618d’, ‘X-Knack-REST-API-Key’: ‘4c515280-4a17-11e6-bfd3-6989fe28c9de’},
data: data,
success: function(response) {
if ( record_ids.length ) {
// Every time a call is made, the array is shifted by 1.
// If the array still has a length, re-run updateRecords()
insertRecords(record_ids.shift(), record_ids, data);
} else {
// We know all records are processed when length = 0
alert('Update complete!');
Knack.hideSpinner();
}
}
})
}
/**** CHANGE VIEW_ID TO YOUR OWN VIEW ID ****/
$(document).on(‘knack-view-render.view_581’, function (event, view) {
// Add an update button
$(’<button id=“update”">Update</button>’).insertAfter("#knack-body");
// Add checkboxes to our table
addCheckboxes(view);
// Click event for the update button
$(’#update’).click(function () {
// We need an array of record IDs
var record_ids = [];
// Populate the record IDs using all checked rows
$('#' + view.key + ' tbody input[type=checkbox]:checked').each(function() {
record_ids.push($(this).closest('tr').attr('id')); // record id
});
Knack.showSpinner();
var BuyerName = Knack.models['view_576'].toJSON().field_430_raw;
alert (BuyerName);
// Define the fields you want to update
var data = {
field_741: record_ids.field_283,
field_762: [record_ids.id],
field_751: record_ids.field_276,
field_751: [record_ids.id],
field_763: BuyerName,
};
// Use the first ID in the array, then pass in the rest of the array
insertRecords(record_ids.shift(), record_ids, data);
$('#update').remove();
})
});