Expand my Community achievements bar.

SOLVED

Connecting two codes to work together

Avatar

Former Community Member

I am trying to connect the following codes to work together. The way it's constructed one code will work but not the other, this is also true when the code is reversed. The 1st part of the code represents a change in the percentage and the 2nd part of the code calculates the actual percentage.

The percentage is formatted as "00.00% When it exceeds 80.00%, I need it to change color and the same for over 90.00%

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

Both are under the formcalc, calculate event.

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

I'll take a look at the form. Thanks again. Just to be clear, i'm not dividing 500.000 by 450.000. I'm dividing $450,000.00 (Four hundred and fifty thousand dollars) into $500,000.00 (Half a million dollars) to get 90.00%.

View solution in original post

18 Replies

Avatar

Level 10

Hi,

I'm believe this script is in the calculate event of LVT1st.

Then the script could look like,

if (FirstLien gt 0 and SalesPrice gt 0) then

          $ = FirstLien / SalesPrice

          if ($ gt 80)then

                    $.fillColor = "239,122,242"

          elseif ($ gt 90) then

                    $.fillColor = "110,0,0"

          else

                    $.fillColor = "208,208,208"

          endif

endif

Avatar

Former Community Member

Thank you. The only color that works is the "else" fill color of 208. The form does not calculate or change with the percentage. This is the code i'm using.

if(FirstLien gt 0 and SalesPrice gt 0) then

           $ = FirstLien / SalesPrice

           if ($ gt 80) then

                                $.fillColor = "500,62,450"

           elseif ($ gt 90) then

                                $.fillColor = "75,100,75"

           else

                                $.fillColor = "210,210,210"

           endif

          

endif

Avatar

Level 10

Hi,

well, use this one,

if (FirstLien gt 0 and SalesPrice gt 0) then

          $ = FirstLien / SalesPrice

          if ($ gt 80 and $ lt 90) then

                    $.fillColor = "50,62,45"

          elseif ($ gt 90) then

                    $.fillColor = "75,100,75"

          else

                    $.fillColor = "210,210,210"

          endif     

endif

Attention: Color values are only have values between 0 and 255.

In your last script you used 450 and 500, which is not possible.

Avatar

Former Community Member

Using the following code, the results are the same.

if(FirstLien gt 0 and SalesPrice gt 0) then

           $ = FirstLien / SalesPrice

if ($ gt 80) then

                                $.fillColor = "50,62,49"

           elseif ($ gt 90) then

                                $.fillColor = "75,100,75"

           else

                                $.fillColor = "210,210,210"

           endif

          

endif

The numbers dont calculate and only the 208 fill color changes.

Avatar

Level 10

Not sure what's wrong at your end, the code works for me.

Can you share your form, so I can check it?

Avatar

Former Community Member

I dont know how to upload a form to this site. The form can be downloaded from box.net.

The link to the form is: https://www.box.com/s/61n32urjw3xglsjnhjg4

Thanks again.

Avatar

Former Community Member

I changed the code today to:

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

if(FirstLien gt 0 and SalesPrice gt 0) then

                $ = FirstLien / SalesPrice

                if ($ gt 80 and $ lt 90) then

                        $.fillColor = "255,13,255"

                elseif ($ gt 90) then

                        $.fillColor = "188,40,29"

                else

                        $.fillColor = "210,210,210"

                endif

endif

It still doesnt work. Does it have something to do with the field being calc-Read only?

Avatar

Level 10

Hi,

I fixed your form.

https://acrobat.com/?d=d6lhDJILedI989QOmwhy0A

Btw. you have several script to change the fill colors in the enter events, which all use invalid color values.

this.fillColor = "400,450,400";

You need to change those scripts.

The color values can only be between "0,0,0" and "255,255,255".

Avatar

Former Community Member

Thanks you so much!!! I havent been able to download the form you fixed but I do appreciate your help. The color codes I used came from Kuler. They are

$.fillColor = "255,13,255"

                elseif ($ gt 90) then

                        $.fillColor = "188,40,29"

                else

                        $.fillColor = "210,210,210"

Can you post the form elsewhere for download?

Avatar

Former Community Member

I downloaded the form. I appreciate your effort, however, the form still does not work. For some reason on your form when you divide the firstlien (450,000.00) into the salesprice of (500,000.00) you get .9% instead of 90.00%. Maybe you changed the format. I can fix that but the color does not change. It needs to change above 80.00% and then above 90.00%. As far as the colors bing coded wrong, I can also fix that with kuler.

Thank you.

Avatar

Former Community Member

I did fix the formatting back to: num{zzz9.99 %}. This allows me to see the percentage as 85.43% instead of .85 or .8543.

Avatar

Former Community Member

I changed the format and re-uploaded the form you fixed, still the only clolor that works is the gray. "208,208,208"

Here is the link: https://www.box.com/s/s44zzcq2sxy3y2gwubfl

Thanks.

Avatar

Level 10

Hi,

well I didn't know what your trying to calculate, but now I know.

The problem is when you devide 500.000 by 450.000 the result is always 0.9 not 90.

Even if your display pattern formats the calculated result into 90% the data behind is still 0.9.

That's why the color never changes in that way you are expecting.

I changed the script to calculate it percents.

var LVT = (100 / SalesPrice) * FirstLien ...

https://acrobat.com/?d=LRInxmXPdibb0xSRkOruXQ

Avatar

Correct answer by
Former Community Member

I'll take a look at the form. Thanks again. Just to be clear, i'm not dividing 500.000 by 450.000. I'm dividing $450,000.00 (Four hundred and fifty thousand dollars) into $500,000.00 (Half a million dollars) to get 90.00%.

Avatar

Former Community Member

I am thankful for your help insolving the color problem. By inserting the code, Look at the yellow highlight (100).

if (FirstLien gt 0 and SalesPrice gt 0) then

           var LVT = (100 / SalesPrice) * FirstLien

           if (LVT gt 80 and LVT lt 90) then

                     $.ui.numericEdit.border.fill.color.value = "239,122,242"

                     ;$.fillColor = "239,122,242"

           elseif (LVT gt 90) then

                     $.ui.numericEdit.border.fill.color.value = "180,0,0"

                     ;$.fillColor = "180,0,0"

           else

                     $.ui.numericEdit.border.fill.color.value = "210,210,210"

                     ;$.fillColor = "210,210,210"

           endif

           $ = LVT   

endif

This caused several other fields not to function correctly. I tried to add * 100 and / 100 to these fields but it does not work.

The only field that was affected was the blendrate field which relies on the calculation of the Firstlien, secondlien and salesprice for weighting. Here is the affected code:

if (rate1>0 and FirstLien>0 and rate2>=0 and Second>=0 and SalesPrice>0 and LTV1st>=0 and LTV2nd>=0)

then Blendrate = (rate1 * FirstLien + rate2 * Second) / SalesPrice / (LTV1st + LTV2nd) ;

endif

Thanks.

Avatar

Former Community Member

You changed the code to:

var LVT = (100 / SalesPrice) * FirstLien.

By adding 100, you solved my problem, thank you. Because another code uses this code it no longer functions. Where can I insert the 100 into the following code?

if(rate1>0 and FirstLien>0 and rate2>=0 and Second>=0 and SalesPrice>0 and LTV1st>=0 and LTV2nd>=0) then Blendrate = (rate1 * FirstLien + rate2 * Second) / SalesPrice / (LTV1st + LTV2nd) ;

endif

Thank you.

Avatar

Former Community Member

I finally figured it out. Thanks for starting me down the right path!.

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