Nathan Grossman
Posts: 0
Joined: Mon Nov 25, 2013 6:17 pm

Create a Total from database items

Thank you. This worked perfectly and I was able to solve my problem

Lonlon
Posts: 0
Joined: Sat Jun 14, 2014 7:04 am

Create a Total from database items

I tried the server code above and it works.

May I know how to filter the amount rather than get the total value of all entry it will filter the value inputed by specific userID. Thank you.

obullei
Posts: 0
Joined: Thu Jun 05, 2014 12:17 am

Create a Total from database items

Hello Lonlon!

Please look here: http://devcenter.appery.io/documentat...

Here you will find information, that you need.

Lonlon
Posts: 0
Joined: Sat Jun 14, 2014 7:04 am

Create a Total from database items

Hi Arina,

Is it for server code? Do you have sample code like what Maryna Brodina gave.

Thank you.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Create a Total from database items

Hello Lonlon,

Please read more about passing parameters to the script for Get method here http://devcenter.appery.io/documentat... (if you want to use Server Code)
Also you can retrieve filtered data with Database Query Service (http://devcenter.appery.io/documentat..., you can find more about queries here http://devcenter.appery.io/documentat...)

Lonlon
Posts: 0
Joined: Sat Jun 14, 2014 7:04 am

Create a Total from database items

Hi Arina,

I included additional variable params as a criteria. It works!

var DB_id='xxxxxxxxxxxxxxxxxx',
collectionName='test',
columnName = 'amount',
location = request.get("locationId");

var params = {}; //Define parameters object
params.criteria = { 'location': locationId //Query criteria:
};

try {
query = Collection.query(DB_id, collectionName, params);
var i, len, value, sum = 0;
for(i = 0, len = query.length; i < len; i++) {
value = parseFloat(query[columnName]);
if (value) {
sum += value;
}
}
response.success({totalSum: sum}, "application/json");
} catch (e) {
response.success({message: e.message, code: e.code}, "application/json");
}

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Create a Total from database items

Thank you for sharing that :)

Return to “Issues”