formula showing sum of all records

Viewing 14 reply threads
  • Author
    Posts
  • May 5, 2020 at 2:13 AM #40475

    Wolfgang
    Participant

    Hello, 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

    Brendan
    Keymaster

    Hi 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

    Wolfgang
    Participant

    Thank 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

    Brendan
    Keymaster

    Can you post your script?

    May 7, 2020 at 1:35 AM #40505

    Wolfgang
    Participant

    first:
    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

    Brendan
    Keymaster

    Ok, 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

    Brendan
    Keymaster

    Should be like this:

    var fieldname_id = 'fld-1af55213294146b68ad048a031b1cb70';
    var total = form.getTotalOfField(fieldname_id);
    total;
    May 7, 2020 at 2:07 AM #40510

    Wolfgang
    Participant

    I 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

    Wolfgang
    Participant

    Yes, the ‘total’ show-command was missing. This will also show the result…
    Thank you Brendan

    May 7, 2020 at 2:19 AM #40512

    Wolfgang
    Participant

    the “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:14

    the “field-name_id” hyphen seems to be wrong!? Using “fieldname_id” as variable, it works.

    May 7, 2020 at 5:56 AM #40513

    Daniel Leu
    Participant

    I 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

    Wolfgang
    Participant

    Hi 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 Leu
    Participant

    Hi Wolfgang, what is your field name?

    May 7, 2020 at 10:14 AM #40516

    Daniel Leu
    Participant

    Now 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);1

    But 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

    Brendan
    Keymaster

    Hi 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

Viewing 14 reply threads

You must be logged in to reply to this topic.