Skip to main content
Known Participant
May 20, 2021
Answered

Pulling data into hidden rows based on a selected value with Javascript

  • May 20, 2021
  • 1 reply
  • 4317 views

My question concerns pulling data into the bottom index based on whether a the score is "Deficient" or not.

if the Score is "Deficient" I want to pull the value from the "Analysis" field, the "Elem" field , and the "Date_af_date" into the corresponding fields in the bottom index. I realize the "Date_af_date" column will need a rename.

Also, I only want as many bottom index rows to appear as there are deficiencies, otherwise I want the rows to be hidden. I wrote some template code for A to for pulling the values but I dont know how to work with hidden rows at all. 

var da = 0

for var (i  = 1, i <= 18, i++){

if (this.getField("AnalysesA"+i).valueAsString == "Deficient");

{

this.getField("Element_Row_"+i).valueAsString = this.getField("ElemA"+i).valueAsString;

this.getField("RankA"+i) = this.getField("A, B, C Ranking_Row_"+i);

this.getField("Date_af_DateA"+i).valueAsDate = this.getField("Correct By(Date)_Row"+i)

}}

if (this.getField("AnalysesA"+i).valueAsString != "Deficient";

{

//rows stay hidden code

}

This topic has been closed for replies.
Correct answer try67

The code itself is correct. I'll need to see the file to be able to troubleshoot this further.

 

And basically all you need in order to move fields around is to change the value of their rect property to the new location.


Sorry, I take it back. You didn't solve one issue.

Change this line:

if (deficientB1 = true)

To:

if (deficientB1 == true)

 

As I wrote before, "=" is used to assign a value, not compare it.

1 reply

try67
Community Expert
Community Expert
May 20, 2021

Again, you have syntax errors in your code. You need to solve those first.

Basically, if the fields are already hidden there's no need to do anything special to keep them that way.

You only need to make them visible when you want to display their values. To do that you need to change their display property, like this:

 

this.getField("FieldName").display = display.visible;

 

If you want to change them back to hidden use the same code, but with "hidden" instead of "visible".

PhilaGuyAuthor
Known Participant
June 24, 2021

I had a couple follow up questions to this one.  Firstly, If I want to hide a row based on an input in another field where would I store it? The field I want hidden, or the input field?

Does this code look correct?

var deficientB1 = false;
if(this.getField("AnalysisB1").valueAsString == "Deficient")  deficientB1 = true;

if (deficientB1 = true)
this.getField("Element_Row_1").display = display.visible;
if (deficientB1 = false)

this.getField("Element_Row_1").display = display.hidden;

 

Also if I want rows to be hidden in the Deficiencies index unless the corresponding Analysis is marked "Deficient" will there be gaps in the index when certain rows are made visible and others arent? If so,  Is there a way to prevent gaps?

try67
Community Expert
Community Expert
June 24, 2021

No, it's not correct. To compare values in JS you must use "==" or "===", not "=". That is used to assign a value, not compare it.