Expand my Community achievements bar.

SOLVED

Change the color of an auto-calculated field

Avatar

Former Community Member

My field is calc-read only. Spent at least the last 3 days on this form. This is a great resource but I cannot find my answer. My form has to do with percentages, If  a field is calculated and the percentage is greater than 50.00% I want to fill the form with color, greater the 80%, same thing. Less than 50%, no fill color.

Tried 100 different scripts, thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I tried simply cutting and pasting the code you sent. It doesnt calculate with this on top.

 

If(FirstLien>0 and SalesPrice>0) then LTV1st = FirstLien / SalesPrice;

endif

if ( LTV1st > 90) then

$.fillColor = "255,255,133"

elseif (LTV1st >= 80 ) then

$.fillColor = "74,165,116"

else $.fillColor = "208,208,208"

endif

If(FirstLien>0 and SalesPrice>0) then LTV1st = FirstLien / SalesPrice;

endif

It calculates but only adds the "else" fill color, it doesnt change the color based on the percentages. I removeed the "oneofchild" code completely until this gets solved.

Thanks again.

when you reverse it like this:

View solution in original post

18 Replies

Avatar

Level 7

You can put something like this (in formcalc):

if ($ > 80) then

form1.fillColor = "17,136,255"

elseif ($ > 50) then

form1.fillColor = "7,136,55"

else form1.fillColor = "255,255,255"

endif

but to make this work you need to save your form as a dynamic form - you can't change the colour of a static form at runtime.

Avatar

Former Community Member

I've placed this code under folmcalc in the calculate event. It doesnt color the form and it prevents the "endif" scenario from functioning.

 

if ($ > 80) then

LTV1st.fillColor = "17,136,255"

elseif ($ > 90) then

LTV1st.fillColor = "7,136,55"

else LTV1st.fillColor = "255,255,255"

endif

Maybe the change event? The White color is working as I can see the border around the field. I am using percentages in these fields not dollars.

Avatar

Former Community Member

By placing the previous code above  the  other code the function, stiil no color.

if ($ > 80) then LTV1st.fillColor = "17,136,255"

elseif ($ > 90) then LTV1st.fillColor = "7,136,55"

else LTV1st.fillColor = "255,255,255"

endif

If(FirstLien>0 and SalesPrice>0) then LTV1st = FirstLien / SalesPrice;

endif

Both are under the calculate event in formcalc.

Avatar

Former Community Member

I have it working now, thank you. Is there a way just to color just the box where the text is instead of the whole box title and all?

Avatar

Former Community Member

My apologies, it is not working. It turned blue one time and is now staying white using the previous code I sent to you.

any advice?

Avatar

Level 7

to colour just the fillable part of the field you do:

xfa.resolveNode("form1.page1.NumericField1.ui.#numericEdit.border.fill.color").value = "17,136,255"

In regards to why it is not working - try putting your code in the exit event of the field.

Avatar

Former Community Member

Thanks again, I'll try the code. I'll let you know if the exit event works, but I dont think it will as I never enter the field. It is auto-calculated from two other fields and I dont overwrite that formula.

Avatar

Former Community Member

Where does the code go? Java or formcalc? under what event?

xfa.resolveNode("form1.page1.NumericField1.ui.#numericEdit.border.fill .color").value = "17,136,255"

???

Does form1 and page1 correspond to my page name? Which is...

  1. Income.#subform[0].LTV1st::calculate -

Avatar

Former Community Member

The exit event does not work and i'm not sure where the xfa codes belongs.

Thanks again.

Avatar

Level 7

the exit event wont work on a calculated field - sorry I forgot that was what you are doing. It should work in the calculate event, but you need to put the if statement underneath your calculations so it has a value to compare.

the xfa code is simply a replacement for the LTV1st.fillColor = "255,255,255" part of your if statement. It is just another way of referencing the field so yes form1.page1.NumericField1 would be replaced with your field names (Income.#subform[0].LTV1st).

Avatar

Former Community Member

once again, thank you. I have found the answer to fill just the text box portion of the field yesterday.

It is: Pmt.ui.oneOfChild.border.fill.color.value = "187,234,160";

That code fills just the calculated portion of my field. My problem is still the code for changing color value once the field is auto-calculated doesnt work. The entire code in the formcalc under Calculate* is:

Income.#subform[0].LTV1st::calculate - (FormCalc, client)

if (LTV1st > 80)then

LTV1st.fillColor = "239,122,242"

elseif ($ > 90) then

LTV1st.fillColor = "110,0,0"

else LTV1st.fillColor = "208,208,208"

endif

If(FirstLien>0 and SalesPrice>0) then LTV1st = FirstLien / SalesPrice;

endif

I havent applied the "oneofchild" code yet as I havent been able to get the "if" code to work. If you place the "if" color code below the calc code the code to calculate percentage no longer functions. The percentages once calculated are formatted like this 80.56% Does that have something with the code not working? We are just using greater than (>) 80?

Great stuff to learn!!!

Many thanks.

Avatar

Former Community Member

I just tried this:

If(FirstLien>0 and SalesPrice>0) then LTV1st = FirstLien / SalesPrice;

endif

if ($ > "80.00 %")then

LTV1st.fillColor = "239,122,242"

elseif ($ > 90) then

LTV1st.fillColor = "110,0,0"

else LTV1st.fillColor = "208,208,208"

endif

I reversed the order of the code and the color did change to a pinkish color, however to calculation did not work. I'm now going to combine both codes to see if that does it. This is the last part of my form, it seems so simple but it is most baffling.

Thanks.

Avatar

Level 7

the calculation if statement isn't working becuase you have a capital "I" in "if". Change it to lowercase and it should work.

Avatar

Former Community Member

I had changed it before your post, it seems to make no difference. Either the number calculates or the color changes, the code the way I have it constructed doesn't do both.

Thanks again.

Avatar

Level 7

can you post the most recent version of your code.

Avatar

Former Community Member

It may be easier to send you the form. The code below is the current one i've tried, it does the auto-calc for the percentage field but not the change in color shade.

LTV1st.ui.oneOfChild.border.fill.color.value = "74,165,116";

var sum = LTV1st;

if ( sum >= 80) then

$.fillColor = "74,165,116"

elseif (sum > 90 ) then

$.fillColor = "255,255,133"

else

$.fillColor = "208,208,208"

endif

if(FirstLien>0 and SalesPrice>0) then LTV1st = FirstLien / SalesPrice;

endif

This is the old code I tried but I had the same results

if ($ > "80.00 %")then

LTV1st.fillColor = "239,122,242"

elseif ($ > 90) then

LTV1st.fillColor = "110,0,0"

else LTV1st.fillColor = "208,208,208"

endif

if(FirstLien>0 and SalesPrice>0) then LTV1st = FirstLien / SalesPrice;

endif

Both codes work for the numeric calc bot not the color shade, if you reverse the order of the code nothing works.

Once I figure this out I'm going to incorporate the "oneofchild" code just to have the fill color of the numeric box change. I tried many variables this weekend but had no luck. and/or while, continue. The answer is probaly easy, I may be overthinking it.

Thanks.

Avatar

Level 7

try this:

if (FirstLien > 0 and SalesPrice > 0) then

LTV1st = FirstLien / SalesPrice

endif

if ( LTV1st > 90) then

$.fillColor = "255,255,133"

elseif (LTV1st >= 80 ) then

$.fillColor = "74,165,116"

else $.fillColor = "208,208,208"

endif

RE: LTV1st.ui.oneOfChild.border.fill.color.value = "74,165,116"

do you want this to change depending on a value or is it always the same? Because at the moment you just have it sitting there.

Avatar

Correct answer by
Former Community Member

I tried simply cutting and pasting the code you sent. It doesnt calculate with this on top.

 

If(FirstLien>0 and SalesPrice>0) then LTV1st = FirstLien / SalesPrice;

endif

if ( LTV1st > 90) then

$.fillColor = "255,255,133"

elseif (LTV1st >= 80 ) then

$.fillColor = "74,165,116"

else $.fillColor = "208,208,208"

endif

If(FirstLien>0 and SalesPrice>0) then LTV1st = FirstLien / SalesPrice;

endif

It calculates but only adds the "else" fill color, it doesnt change the color based on the percentages. I removeed the "oneofchild" code completely until this gets solved.

Thanks again.

when you reverse it like this:

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