I need to update a connection field via API/JS - it seems you need to match the ID in order for Knack to pick it up and so far I have been unsuccessful in doing so.
Via the web interface we are able to set the connection field to the current logged in user via a button action - anyone know how I can recreate this via the api?
Something to the effect of:
var adminID = Knack.getUserAttributes().id;
or
var adminName = Knack.getUserAttributes().name;
var data2 = {
field_171: ‘Yes’,
field_175: todayDate.toJSON(),
field_245: data.field_245_raw[0].id + adminID This is the issue
}
with an ajax call
var selectedRecords2 = record_ids2.length + 1
function updateRecords2(id, records, data2) {
$.ajax({
url: ‘https://usgc-api.knack.com/v1/objects/object_2/records/’ + id,
type: ‘PUT’,
headers: {‘X-Knack-Application-ID’: ‘’,
‘X-Knack-REST-API-Key’: ‘’},
data: data2,
success: function(response) {
if (record_ids2.length > 0) {
// every time a loop is made, the array is shifted by 1.
// if the array still has a length greater than 0, re-run another updateRecords loop
setTimeout(updateRecords2(record_ids2.shift(), record_ids2, data2), myDelay2);
}
else {
alert(‘Updating ’ + selectedRecords2 + ’ records.’);
Knack.hideSpinner();
window.location.reload(true);
// Knack records are updated now
}
},
error : function(response) {
alert(‘API error’);
Knack.hideSpinner();
}
})
}
})
How can I set field_245 (a connection field) to the current logged in user without affecting the record connections.