Sum of Child Records on Parent Edit

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);
})
});

Martin, indeed you are right.

Maybe there is something wrong in your call. Try to set the filter like this:

RequestFilters = {
'rules': [
{
'field':'field_450',
'operator':'is',
'value': parentID
}
]
};

This should work.

Ciao

Davide

When I am editing the page, I do not have the option of adding a summed field to the page, I can add equations, but not sum's or counts. I suspect there are not stored fields, however calculated when the page is rendered.

Martin

You can add the field in the edit form as a read-only field.