I am trying to add a field to a parent record that is the sum of child records. The sum works, however the Knack field is not available in the edit form. So I thought I would a JavaScript function to solve the problem.
I looked at the code samples, however I can't seem to get everything to work correctly.
I have confined that the parentID is correct and the field_450 and object 28 is the child records. The code does run at the correct time, just I get 0 as the number of records returned.
Here is the code
$(document).on('knack-view-render.view_1109', function(event, view, parentData) {
var KnackAppID = "xxxxxx"
var KnackAPIKey = "yyyyyy"
var parentID = parentData.id
RequestUrl = 'https://api.knack.com/v1/objects/object_28/records';
RequestFilters = [
{
'field':'field_450',
'operator':'is',
'value':[parentID]
}
];
var fullRequestUrl = RequestUrl + '?filters=' + encodeURIComponent(JSON.stringify(RequestFilters));
$.ajax({
url: fullRequestUrl,
type: 'GET',
headers: {
"X-Knack-Application-Id": KnackAppID,
"X-Knack-REST-API-Key": KnackAPIKey
}
}).done(function(childData) {
console.log(childData);
})
});