Pete Gombert
Posts: 0
Joined: Tue Mar 18, 2014 2:42 pm

Sum a column in the database using server code for a certain set of records

I have a custom collection in the database called Account_Transactions. In this collection there is a column called Account_ID and a column named Amount. I need to sum all of the Amount column records Where the Account_ID = a specific Account_ID parameter passed from the application.

I also need to create a service to sum all Amounts grouped by the Account_ID.

I have played around with for loops to do this, but I am struggling.

Thanks

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Sum a column in the database using server code for a certain set of records

Hello!

On service success event add code wich will count sum in a loop.
Please check errors in console, perhaps you've made some mistakes in column name.

Pete Gombert
Posts: 0
Joined: Tue Mar 18, 2014 2:42 pm

Sum a column in the database using server code for a certain set of records

I am struggling to access the proper field in the JSON results. I can't seem to get just the Amount to return as an array so I can loop through it. Or if I get the entire JSON result how can I just stringify the appropriate column?

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

Sum a column in the database using server code for a certain set of records

Hello,

The whole service response will be available in data variable on success event. Please, provide a screenshot of the service response tab and code that you use for sum calculating. We'll see where the error is.

Pete Gombert
Posts: 0
Joined: Tue Mar 18, 2014 2:42 pm

Sum a column in the database using server code for a certain set of records

I agree that the entire service response is available, but I only want to SUM one column - how do I refer to that column in JS.

var balance = JSON.????
var balance = data.????

I am not sure how to refer to only one column in the response

Thanks

Pete Gombert
Posts: 0
Joined: Tue Mar 18, 2014 2:42 pm

Sum a column in the database using server code for a certain set of records

Forget it - I figured it out on my own. For those of you having the same issue this is the code that ended up working (pretty simple once you know how to refer to the right column:
Image

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

Sum a column in the database using server code for a certain set of records

We are glad that you got it!

Return to “Issues”