# Copy record with fields from multiple tables

**URL:** <https://forums.knack.com/t/copy-record-with-fields-from-multiple-tables/17754>\
**Category:** API & Custom Code\
**Created:** [August 23, 2024, 2:09pm UTC](https://forums.knack.com/t/copy-record-with-fields-from-multiple-tables/17754 "2024-08-23T14:09:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![CathyHMcB](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/cathyhmcb/32/1305_2.png) [@CathyHMcB](https://forums.knack.com/u/CathyHMcB)\
**Post date:** [August 23, 2024, 2:09pm UTC](https://forums.knack.com/t/copy-record-with-fields-from-multiple-tables/17754/1 "2024-08-23T14:09:53Z")

</div>

I have JS code that copies a record. It worked perfectly until I did a little database redesign where some of the fields being copied were moved to other tables. Any ideas what I need to do to get it working again?  
Included is the code that worked. The three fields not copying are:  
data.field\_453 //Venue Name  
data.field\_527 //Customer Name  
data.field\_551 //Requestor Name

I’m not a coder by trade, I don’t know JS, and I’m winging it with everyone’s help. And y’all continue to provide wonderful support. Thank you.

* * *

$(document).on(‘knack-view-render.view\_352’, function(event, view, data) {  
// Do something after the view renders - copy button is on scene\_33/views/view\_352  
console.log(data)  
var duplicateData = {  
field\_9: data.field\_9, //Group  
field\_11: data.field\_11, //Event Start Time  
field\_12: data.field\_12, //Event End Time  
field\_14: data.field\_14, //Referral Source  
field\_16: data.field\_16, //Type of Event  
field\_220: data.field\_220, //Set Rate?  
field\_222: data.field\_222, //Initial Contract/Negotiated Price  
field\_225: data.field\_225, //Will Invoice?  
field\_239: data.field\_239, //Terms  
field\_244: data.field\_244, //Lead Owner  
field\_358: data.field\_358, //Pieces  
field\_453: data.field\_453, //Venue Name from Lookup of Venue Table  
field\_527: data.field\_527, //Customer Name from Lookup of Customer Table  
field\_538: data.field\_538, //Event Pre-Audit  
field\_551: data.field\_551 //Requestor from Lookup of Requestor Table  
}

// Add a button to execute the action  
$(‘#’ + view.key).prepend(‘Copy Record’);

// Add the duplicate function to the button we just added  
document.getElementById(‘copy-button’).addEventListener(‘click’, function () {  
Knack.showSpinner();  
$.ajax( {

// Change object here to match your record’s object #  
url: ‘[https://api.knack.com/v1/pages/scene\_xx/views/view\_xxx/records](https://api.knack.com/v1/pages/scene_xx/views/view_xxx/records)’,  
type: ‘POST’,  
headers: {  
‘Authorization’: Knack.getUserToken(),  
‘X-Knack-Application-Id’: Knack.application\_id,  
‘X-Knack-REST-API-Key’:‘knack’},  
data: duplicateData,  
success: function(response) {  
alert(‘Record Copied! Find the record on New Records tab, add the new event date and set the status!’);  
Knack.hideSpinner();  
}  
});  
});

});

* * *
