Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

getting calculated fields to appear red when negative

I have a table in a dynamic form, which can add and delete rows using buttons, which has calculated fields in the footer row and the far right column. The calculated fields use the FormCalc sum command to either add values from the column above or the row to the left. I am trying to get these values to appear in red when they are negative (I already have the display pattert set as ($zzz,zz9.99), but I also need the red font). I have successfully done this for the data entry cells in each row using the following JavaScript (runs on the exit event):


I cannot figure out how to keep the calculated cells updating as the data they depend on changes, and also get the font to change color if the sum goes below zero, especially since I am using two different languages. Help!
0 Replies
Can I do that? The sum calculation (in the calculate event) is in FormCalc, and the "color" code is in JavaScript. It seems to me that you can only use one language for a particular event.


Level 10
You are right change the color command to FormCalc. It is only the if statement that needs to change the rest remains the same.
Sorry - you've lost me. As far as I can tell, I can oly pick one language for a given event. If that's true, I can figure out how to do the sum in JavaScript (currently in FormCalc) and I can't figure out how to do the coloring in FormCalc (currently in JS).


Level 10
Java script has no SUM function so leave that in FormCalc and change the color mode command to FormCalc. I think it would be something like this:



Making progress, but now I have a "program flow" problem. Here's some code (from my Script Editor window):

----- form1.Table1.FooterRow.tFY10::calculate: - (FormCalc, client) --------------------------------

if(tFY10.rawValue<0) then tFY10.font.fill.color.value="255,0,0" endif


tFY10 is the field this code is associated with. The column above is called FY10 and includes one or more rows in a dynamic table. If the code above is entered, the calculation works, but the coloring effect is always "one step behind" - i.e the first time I enter numbers above that make the result negative, nothing happens, but the next time it will turn red if the sum stays negative. However, if I reverse the lines of code, the calculation never executes (and $0 always shows in tFY10). I can't find any variation that works.
Disregard - I figured it out. It took a bit more code than I anticipated. Here's an example from one of the data entry cells:

//data entry cell

if (FY10.rawValue<0) then FY10.font.fill.color.value="255,0,0"

else FY10.font.fill.color.value="0,0,0"


//row total

if (form1.Table1.Row1.FYDP.rawValue<0) then FYDP.font.fill.color.value="255,0,0"

else FYDP.font.fill.color.value="0,0,0"


//column total

if (form1.Table1.FooterRow.tFY10.rawValue<0) then form1.Table1.FooterRow.tFY10.font.fill.color.value="255,0,0"

else form1.Table1.FooterRow.tFY10.font.fill.color.value="0,0,0"


//table total

if (form1.Table1.FooterRow.tFYDP.rawValue<0) then form1.Table1.FooterRow.tFYDP.font.fill.color.value="255,0,0"

else form1.Table1.FooterRow.tFYDP.font.fill.color.value="0,0,0"