Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Basic calculations in LiveCycle

Avatar

Former Community Member

I'm trying to create basic calculations in a form that I am creating in LiveCycle Designer. Has anyone does this, and can you please give me some help? I don't understand the instructions in the Help feature or the book that I have.  Here is what I am trying to do:

Text Field A 100 (manual entry)

Text Field B 75   (manual entry)

Text Field C 25   (Result of calculation of A - B = C)

Then:

Text Field D 2    (manual entry)

Text Field E 50  (Result of calculation of C X D = E)

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I prefer to use Javascript so on the Calculate event of the C field you would use this command:

this.rawValue = FieldA.rawValue -Field B.rawValue

Then on E Field's calculate event you woudl use this command:

this.rawValue = FieldC.rawValue * FieldD.rawValue

If you woudl prefer to use FormCalc you woudl still use the Calculate event and on FieldC the command woudl be:

FieldA - FieldB

On the calculate of Field E

FieldC * FieldD

Hope that helps

paul

View solution in original post

11 Replies

Avatar

Correct answer by
Former Community Member

I prefer to use Javascript so on the Calculate event of the C field you would use this command:

this.rawValue = FieldA.rawValue -Field B.rawValue

Then on E Field's calculate event you woudl use this command:

this.rawValue = FieldC.rawValue * FieldD.rawValue

If you woudl prefer to use FormCalc you woudl still use the Calculate event and on FieldC the command woudl be:

FieldA - FieldB

On the calculate of Field E

FieldC * FieldD

Hope that helps

paul

Avatar

Former Community Member

Okay, Paul, I have another question...  I'm not even sure that it is possible.

Do you know how to force a positive result?  Here is my example of what I am trying to say:

Value A: $1.00 minus Value B $1.10 equals -$0.10 (this comes out to a negative, but I need to just show it as a dollar amount not as a negative)

Not all situations will result in a negative number - so I need to always just show it as a dollar figure regardless of positive or negative.

Avatar

Former Community Member

There is a native javascript function to get the absolute value of a number .....lets assume your fields are called Field1 and Field2. Then the command woudl be:

Total.rawValue = Math.abs(Field1.rawValue - Field2.rawValue)

Paul

Avatar

Former Community Member

It is not working.  It is no longer giving me any value. Bummer.  Any other ideas?  Could it be because I have the Display Pattern as a with a dollar sign?  I'm thinking not, but hey, just checking.

Avatar

Former Community Member

Works fine for me ...here is a sample ...the code is on the calculate of the total field. Oh ....and make sure your fields are numeric.

Paul

Avatar

Former Community Member

Could it be because I am using LiveCycle Designer 8.0?

Avatar

Former Community Member

Nope .....did you set the language to javascript?

Paul

Avatar

Former Community Member

Yes the language is set to javascript.

How can I send you a file that I created with the portion of the form that I cannot get to work?  I've looked for a way to upload to here, but I don't see anything.

Avatar

Former Community Member

Email it to LiveCycle8@gmail.com . Please include a description of the issue.

Paul

Avatar

Former Community Member

THANK YOU SO MUCH!!!!!!!  I cannot tell you enough at how much I appreciated your help!  I hope that you have an awesome day!

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] ----