Page 1 of 1
Sum a column in the database using server code for a certain set of records
Posted: Tue Mar 25, 2014 2:03 pm
by Pete Gombert
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
Sum a column in the database using server code for a certain set of records
Posted: Tue Mar 25, 2014 2:54 pm
by Maryna Brodina
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.
Sum a column in the database using server code for a certain set of records
Posted: Tue Mar 25, 2014 3:10 pm
by Pete Gombert
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?
Sum a column in the database using server code for a certain set of records
Posted: Tue Mar 25, 2014 3:28 pm
by Nikita
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.
Sum a column in the database using server code for a certain set of records
Posted: Tue Mar 25, 2014 5:18 pm
by Pete Gombert
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
Sum a column in the database using server code for a certain set of records
Posted: Tue Mar 25, 2014 7:12 pm
by Pete Gombert
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:
Sum a column in the database using server code for a certain set of records
Posted: Tue Mar 25, 2014 7:22 pm
by Nikita
We are glad that you got it!