# Copy records from one object to another via API

**URL:** <https://forums.knack.com/t/copy-records-from-one-object-to-another-via-api/6934>\
**Category:** API & Custom Code\
**Created:** [October 17, 2018, 9:36am UTC](https://forums.knack.com/t/copy-records-from-one-object-to-another-via-api/6934 "2018-10-17T09:36:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheBug71303](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@TheBug71303](https://forums.knack.com/u/TheBug71303)\
**Post date:** [October 17, 2018, 9:36am UTC](https://forums.knack.com/t/copy-records-from-one-object-to-another-via-api/6934/1 "2018-10-17T09:36:21Z")

</div>

I have an object containing evaluation questions (template). Every time a new evaluation is created, I would like to copy all relevant evaluation questions from the template to another object.

I almost have it working, I am able to get the code to insert all the questions into the other object, my only problem is that I would like more than just the question header, I also need the weight of the question. So bottom line, how do I copy more than just one field from a source to a destination?

Here is the almost working code:

What I need is to insert the value of field\_128 instead of '1', where the red line is below.

 ![](https://support.knack.com/hc/user_images/SmDRVlvJBktrzAr6DmYNlQ.png)

Update:

Got it working with the following adjustments:

 ![](https://support.knack.com/hc/user_images/hlm2RT4A2WF85HVIcW7IPQ.png)  
  
Code:

//Functions to insert evaluationlist items for new evaluation  
var app\_id = Knack.app.id;  
var redirect = function (total, CheckListType, job) {if(total \< 1) {Knack.hideSpinner(); window.location.replace('#job')} };

//Set variables to be used later  
$(document).on('knack-record-create.view\_14', function (event, view, record) {  
 var CheckListType = $('#view\_14-field\_73').val();  
 var job = record.id;  
 var user = Knack.getUserToken();  
 var headers = { "Authorization": user, "X-Knack-Application-ID": app\_id, "Content-Type":"application/json"}

$.ajax({  
 url: '[https://api.knack.com/v1/scenes/scene\_21/views/view\_26/records/](https://api.knack.com/v1/scenes/scene_21/views/view_26/records/)' + CheckListType,  
 type: 'GET',  
 headers: headers,  
 success: function (data) {  
 Knack.showSpinner();  
 var EvaluationItems = data.field\_71\_raw;  
 var WeightItem = data.field\_128\_raw;  
 var total = EvaluationItems.length;  
 var counter = 0;  
   
 EvaluationItems.forEach(function (Item) {  
 var data = { field\_66: job, field\_65: Item.id, field\_130: WeightItem[counter]};  
 console.log("Counter: " + counter);  
 counter++;  
 $.ajax({  
 url: '[https://api.knack.com/v1/scenes/scene\_17/views/view\_23/records/](https://api.knack.com/v1/scenes/scene_17/views/view_23/records/)',  
 type: 'POST',  
 headers: headers,   
 data: JSON.stringify(data),  
 success: function (response) {  
 total--;  
 console.log('Evaluation items added!!!');  
 redirect(total, CheckListType, job);  
 }  
 })  
 });  
 }  
 });  
});

---

<div class="post-metadata">

**Author:** ![TheBug71303](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@TheBug71303](https://forums.knack.com/u/TheBug71303)\
**Post date:** [October 17, 2018, 10:24pm UTC](https://forums.knack.com/t/copy-records-from-one-object-to-another-via-api/6934/2 "2018-10-17T22:24:08Z")

</div>

Thanks, took me a while to get it working, but quite usefull in many scenarios, so happy if others can benefit too.

---

<div class="post-metadata">

**Author:** ![BradStevens](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/bradstevens/32/140_2.png) [@BradStevens](https://forums.knack.com/u/BradStevens)\
**Post date:** [October 17, 2018, 10:18pm UTC](https://forums.knack.com/t/copy-records-from-one-object-to-another-via-api/6934/3 "2018-10-17T22:18:26Z")

</div>

Well done working it out - and I'm impressed with the clarity of your code, something I need to work on so thanks for the pointers!
