I’m trying to create a record that contains a date field, and failing badly! Nothing is getting written for the date at all.
The code is catching the submit action on one record, and creating a new record in another table that uses the date field from the submitted record.
Here’s the (minimal) code:
$(document).on('knack-form-submit.view_19', function(event, view, record) {
var user = Knack.getUserAttributes().id;
if (user) {
console.log("Close Date: %s", record.field_78);
console.log("Close Date raw: %o", record.field_78_raw);
$.ajax({
url: 'https://api.knack.com/v1/pages/scene_50/views/view_66/records',
type: 'POST',
async: false,
headers: {'X-Knack-Application-Id': 'XXXXXXXXXXXXXXXXX', 'X-Knack-REST-API-Key': 'knack', 'Authorization': Knack.getUserToken(), 'Content-Type': 'application/json'},
data: JSON.stringify({'field_95': record.field_78_raw.date}),
success: function (response) {
console.log("Record created");
},
error: function(response){
console.log(response);
}
});
}
});
field_95 is a date field in the destination record, field 78 in the source record, both formatted as mm/dd/yyyy.
I’ve tried all of the following, all with no luck:
data: JSON.stringify({'field_95': record.field_78})
data: JSON.stringify({'field_95': record.field_78_raw})
data: JSON.stringify({'field_95': record.field_78_raw.date})
data: JSON.stringify({'field_95': {'date': record.field_78_raw.date})
The console shows what I would expect:
Close Date: 11/30/2021
VM16773:12 Close Date raw: {date: “11/30/2021”, date_formatted: “11/30/2021”, hours: “12”, minutes: “00”, am_pm: “AM”, …}
Any suggestions?