How to allow users to duplicate a record?

I searched and couldn’t find a simple answer here or in KTL. I would like users to be able to make a copy of a single record at a time, and include pre-defined fields to be replicated into the new record. Is there a simply way to do this? I’ve tried using some API/js code I found here, but Claude has me going in circles trying to get it to work error-free.

Here’s what I’ve got so far, but I keep getting CORS errors trying to run it:

$(document).on(‘knack-view-render.view_634’, function(event, view, data) {

// Add a duplicate button to the view header

var $button = $(‘Duplicate Record’);

$(‘#view_634 .view-header’).append($button);

$button.on(‘click’, function() {

var recordId = data.id; // The current record’s ID

// Fields you want to copy — map field keys to their values

var newRecord = {

  field_440: data.field_440_raw || data.field_440,

  field_441: data.field_441_raw || data.field_441,

  field_1497: data.field_1497_raw || data.field_1497

// Add/remove fields as needed

};

// POST the new record to your object

$.ajax({

  url: Knack.api_url + '/v1/objects/object_35/records',

  type: 'POST',

  headers: {

‘X-Knack-Application-Id’: Knack.application_id,

‘X-Knack-REST-API-Key’: ‘knack’,

‘Authorization’: Knack.getUserToken()

// ← Remove Content-Type header entirely

},

// Use contentType and processData instead

  contentType: 'application/json',

  data: JSON.stringify(newRecord),

  success: function(response) {

    alert('Record duplicated! New record ID: ' + response.id);

},

  error: function(xhr, status, err) {

    console.error('Error:', xhr.responseText);

}

});

});

});

Hi

Wouldn’t the simplest solution for this situation be to use the KTL bulk operations feature with an Action Link?

Dean

@JDWorleyKY,

The KTL’s Bulk Duplicate is designed to accomplish just that.

1- Did you try it?
2- Where did it fail? Connected fields, field types or format unsupported, etc
3- Can you provide us with your typical use case?

Norm

I’ve just found a KTL bug about Bulk Duplicate, where it wouldn’t copy anything if at least one top header checkbox was selected. The documentation states that if none are checked, then all fields are copied, but this wasn’t implemented as such.

I’ve fixed the bug today, and will deploy soon.

In the meantime, you can get around this by selecting all checkboxes manually.

Tip: Ctrl+Click one of them toggles them all

Norm