Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Using Tap Forms › formula showing sum of all records
Tagged: all records, Calculation, sum total
- This topic has 14 replies, 3 voices, and was last updated 4 years, 6 months ago by Brendan.
-
AuthorPosts
-
May 5, 2020 at 2:13 AM #40475
WolfgangParticipantHello, I need the formula in my own layout to get the amount of all records (for example the sum of all invoices).
It must be the formula that is automatically in the standard layout in the calculation row (sum, average, min, max, number). A new calculation field and sum (fieldname) etc. does not work …May 6, 2020 at 8:33 PM #40495
BrendanKeymasterHi Wolfgang,
Sure. You can get that.
In the JavaScript API docs there’s this function:
var total = form.getTotalOfField(field_id);
That’ll do it. It returns the same value as you see displayed at the bottom of the records list view.
Hope that’s what you’re looking for.
Thanks!
Brendan
May 7, 2020 at 1:24 AM #40498
WolfgangParticipantThank you for the info. But no result is shown …
I use 2 field scripts (see screenshots).
– one with the line you mentioned above
– one using the formula of the list in the script window
No entries in the fields!Wolfgang
Attachments:
You must be logged in to view attached files.May 7, 2020 at 1:33 AM #40501
BrendanKeymasterCan you post your script?
May 7, 2020 at 1:35 AM #40505
WolfgangParticipantfirst:
var total = form.getTotalOfField(“fld-1af55213294146b68ad048a031b1cb70”);second:
var fieldname_id = ‘fld-1af55213294146b68ad048a031b1cb70’;
var total = form.getTotalOfField(fieldname_id);May 7, 2020 at 2:04 AM #40507
BrendanKeymasterOk, well that should work.
And sorry, for some reason I didn’t see your attachments before.
Did you return the values later on in your script? Or did you just define the vars?
May 7, 2020 at 2:06 AM #40508
BrendanKeymasterShould be like this:
var fieldname_id = 'fld-1af55213294146b68ad048a031b1cb70'; var total = form.getTotalOfField(fieldname_id); total;
May 7, 2020 at 2:07 AM #40510
WolfgangParticipantI tried and found:
the online manual only says:
form.getTotalOfField (“fld-1af55213294146b68ad048a031b1cb70”);or
fieldname_id = ‘fld-1af55213294146b68ad048a031b1cb70’;
form.getTotalOfField(fieldname_id);this works …
May 7, 2020 at 2:10 AM #40511
WolfgangParticipantYes, the ‘total’ show-command was missing. This will also show the result…
Thank you BrendanMay 7, 2020 at 2:19 AM #40512
WolfgangParticipantthe “get command” show this:
var field-name_id = ‘field-id’;
but I always get an error message:
TotalUmsatz: SyntaxError: Unexpected token ‘-‘. Expected ‘;’ after variable declaration., line:14the “field-name_id” hyphen seems to be wrong!? Using “fieldname_id” as variable, it works.
May 7, 2020 at 5:56 AM #40513
Daniel LeuParticipantI don’t think that the ‘-‘ is valid in the variable name. Try using
var field_name_id = ‘field-id’;
of
var fieldName_id = ‘field-id’;
May 7, 2020 at 8:54 AM #40514
WolfgangParticipantHi Daniel,
that’s exactly what I wanted to say.
In Tap Forms in the script field the variable of the formula “get total of field from form” is displayed with “-” and always gave me an error message.
That’s why I removed the “-” and used “fieldname” or “field_name” …May 7, 2020 at 10:08 AM #40515
Daniel LeuParticipantHi Wolfgang, what is your field name?
May 7, 2020 at 10:14 AM #40516
Daniel LeuParticipantNow I see it….
Brendan, double-clicking on ‘Get total of field from form’ snippet returns
`var field-name_id = ‘field-id’;
var total = form.getTotalOfField(field-name_id);1But the
-
is not a valid character to be used in a Javascript variable name.The same applies to the other three
Get...
snippets.May 7, 2020 at 10:19 AM #40517
BrendanKeymasterHi Wolfgang,
Ah ok. I understand now. Ya, I see that there was a problem with my variable substitution code where Tap Forms replaced the tokens in my snippet code. I’ve just fixed this for the next update.
This happened when you double-clicked on the
get total of field from form
snippet.Thanks for reporting this issue.
Brendan
-
AuthorPosts
You must be logged in to reply to this topic.