Expand my Community achievements bar.

SOLVED

Java Script sum calculation

Avatar

Level 2

Hi I'm looking for help for what I suppose would be an easy question based on other posts I've read.

I'm new to livecycle ES and I have spent the better part of my adult life figuring out how to make new form fields appear after selecting a button.  Each entry has a "cost" numeric field (each with the same binding name) and at the bottom of the form I have a "total" num field which I want to display the sum of all the completed cost fields.  I have used a script that is supposed to sum up the same instance of the field name (ex. cost[*]) but it doesn't work.

Any help would be appreciated.

Stewb

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

FormCalc provides coding brevity and functions that are very good for calculating table row and column totals.

For example, to calculate a row total.

// form.page1.budget.costs.row[0].total::calculate - (FormCalc, client)

$.rawValue = beer + food + other

For example, to calculate a column total.

// form.page1.budget.totalCosts.totals.food::calculate - (FormCalc, client)

$.rawValue = sum(form.page1.budget.costs.row[*].food)

Steve

View solution in original post

2 Replies

Avatar

Correct answer by
Former Community Member

FormCalc provides coding brevity and functions that are very good for calculating table row and column totals.

For example, to calculate a row total.

// form.page1.budget.costs.row[0].total::calculate - (FormCalc, client)

$.rawValue = beer + food + other

For example, to calculate a column total.

// form.page1.budget.totalCosts.totals.food::calculate - (FormCalc, client)

$.rawValue = sum(form.page1.budget.costs.row[*].food)

Steve

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----