Page 1 of 2

How do i calculate the sum of 2 or more numbers in the database

Posted: Tue Mar 11, 2014 9:52 pm
by David6727976

i would like to calculate the sum of 2 or more numbers in my database and return the result to another column in my database. please could you assist with the code i need to apply or perhaps the functions needed to do this.


How do i calculate the sum of 2 or more numbers in the database

Posted: Tue Mar 11, 2014 9:54 pm
by David6727976

How do i calculate the sum of 2 or more numbers in the database

Posted: Tue Mar 11, 2014 10:16 pm
by Nikita

Hello,

You should create two services:
1)for reading two values from DB and saving it to localStorage
2)for recording result of addition to DB


How do i calculate the sum of 2 or more numbers in the database

Posted: Tue Mar 11, 2014 10:40 pm
by David6727976

Hi Nikita. i know how to create the service to write and read from the DB and save to the localStorage. However i dont know how to create the script to add or multiply the values to get the to get a score as in the above image (outsidescorefield) please could you assist me with understanding how to do this.


How do i calculate the sum of 2 or more numbers in the database

Posted: Wed Mar 12, 2014 5:21 am
by Igor

Hi,

Below are the steps how to do this:

1 Get db row by read/list/query service.
2 In success event for read/list/query service add following JS:
pre
//If service not returns an object.
if(!data || data[0])
return;

var obj = data[0];
var summ = parseInt(obj.outsidewindowsField) + parseInt(obj.outsidesignageField) + parseInt(obj.outsideentranceField);
//then set sum as value for input of create/update service.
/pre

3 Run create/update service


How do i calculate the sum of 2 or more numbers in the database

Posted: Wed Mar 12, 2014 9:06 pm
by David6727976

Hi Igor

Please could you assist as i dont know what to do next.
This is what i have done so far.

  1. i created a List service for the outside database collection.

  2. i then read the above 3 fields into LocalStorage variables with in the List service

  3. i then create a Javaacript within the List service and included the above code you supplied.

  4. i then linked this java script to the database field call outsideScoreField.

    i dont think im on the right track here.
    From your example above you want me to find the db row, i dont know how to do this. please could you advise.


How do i calculate the sum of 2 or more numbers in the database

Posted: Wed Mar 12, 2014 10:22 pm
by David6727976

Hi Igor.

can i not create an event on the front end to add the values in the 3 label fields together and place the answer into another label field before running the initial create service. then when i create the service i only have to write the 4 label field to the database. that way i dont have to run a list/read or update service


How do i calculate the sum of 2 or more numbers in the database

Posted: Wed Mar 12, 2014 11:14 pm
by Illya Stepanov

Hi David,

Please follow this tutorial: http://docs.appery.io/tutorials/build... -- it shows how to make search in db.

Also you should learn this document http://docs.appery.io/documentation/b... -- in the part of "Query service".

After you will pass all this docs many questions disappear.

But if you still have questions, please post us screenshots - what you have done exactly and what problems you have there.


How do i calculate the sum of 2 or more numbers in the database

Posted: Thu Apr 10, 2014 2:20 am
by Gregory Hovagim

Hi, I love appery.io and I've been telling all my friends about it. In fact, I'll be showing a class of interested robotics students how to develop their first apps. I'm on a short fuse for a deadline for the team and I could use your urgent help to get over the last hurdle of adding two (or more numbers) in my database, and then saving that value to the database itself. If you can be OVERLY specific that'd be a tremendous help as I'm trying to learn some of these details. Here are the screenshots.

I'm trying to add: HIGH GOAL and LOW GOAL Scores together, and save it to ESTIMATED Score. (I will add the complexity of multiple scores together on my own) I'm not understanding the details provided to the other user who asked a similar question. Big thank you!

Image
Image

Image

Image


How do i calculate the sum of 2 or more numbers in the database

Posted: Thu Apr 10, 2014 3:00 am
by Alena Prykhodko

Hi Gregory.

Please follow the steps below:

1 You have two fields (hGoal and lGoal)

2 You have some create/save service called "robot_create"

3 Open data tab.

4 Click "Edit mapping"

5 Navigate to the Request tab.

7 Make mapping from one of these fields to the "ESTIMATEDScore" db field.
Image

8 Click "Add JS" for this field.

9 JS editor appears. Populate it with following code:
pre

var lG = parseInt(Appery("lGoal").val());

var hG = parseInt(Appery("hGoal").val());

var result = lG + hG;

return result;/pre

Note: "lGoal" and "hGoaL" are your input labels. You have to replace it with yours.