Expand my Community achievements bar.

getting calculated fields to appear red when negative

Avatar

Former Community Member
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):



if(cellname.rawValue<0){cellname.font.fill.color.value="255,0,0";}



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!
7 Replies

Avatar

Former Community Member
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.

Avatar

Former Community Member
You are right ...so change the color command to FormCalc. It is only the if statement that needs to change the rest remains the same.

Avatar

Former Community Member
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).

Avatar

Former Community Member
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:



if(cellname.rawValue<0)then

cellname.font.fill.color.value="255,0,0"

endif

Avatar

Former Community Member
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

sum(Table1.Row1[*].FY10[*])



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.

Avatar

Former Community Member
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"

endif



//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"

endif



//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"

endif



//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"

endif