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.
Update:
Got it working with the following adjustments:
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/' + 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/',
type: 'POST',
headers: headers,
data: JSON.stringify(data),
success: function (response) {
total--;
console.log('Evaluation items added!!!');
redirect(total, CheckListType, job);
}
})
});
}
});
});