Copy link to clipboard
Copied
So this is one that has been stumping me for a bit. ive tried and failed just to get the script to add to and print from an array based on the value of drop down box. i am creating a document for instructors to use as a tool to generate the text that can be copy and pasted into a "report card". There are 6 assessments the students must complete throughout the course. All assessments are rated as either Met standard, Exceeded Standard, and Far Exceeded standard. I have all 6 assessments listed out and have a corresponding drop down list containing Met, Exceeded and Far Exceed. I have a field box below that i am trying to create a custom calculation script. What the end goal would be is to create a script that groups all of these items together in arrays by their test rating and prints it later on in a list. Here is a sample at what i am attempting, but only factors for 2 of the 6 tests and probably has a lot of issues:
var metArray = [];
var exceedArray = [];
var fexceedArray = [];
var Var1 = this.getField("Test1");
if(Var1 == "Met");{
metArray.push('Public Speaking');
}
else if(Var1 == "Exceed");{
exceedArray.push('Public Speaking');
}
else if(Var1 == "Far Exceed");{
fexceedArray.push('Public Speaking');
}
var Var2 = this.getField("Test2");
if(Var2 == "Met");{
metArray.push('ABC presentation');
}
else if(Var1 == "Exceed");{
exceedArray.push('ABC presentation');
}
else if(Var1 == "Far Exceed");{
fexceedArray.push('ABC presentation');
}
var Var30 = *** PRINT 'FAR EXCEEDED' ARRAY SEPARATED BY COMMA***
var Var20 = *** PRINT 'EXCEEDED' ARRAY SEPARATED BY COMMA***
var Var10 = ***PRINT 'MET' ARRAY SEPARATED BY COMMA***
event.value = this.getField("Name").valueAsString + " Far Exceeded the course standard during his: " + ***Var30*** + " evaluation." + this.getField("Name").valueAsString + " Exceeded the course standard during his: " + ***Var20*** + " evaluation." + this.getField("Name").valueAsString + " Met the course standard during his: " + ***Var10*** + " evaluation."
Printed version would look like:
Mr. Adobe far exceed the course standard during his Public Speaking, ABC Presentation, and DEF presentation evaluations. Mr. Adobe exceed the course standard during his 2nd essay evaluation.
Mr. Adobe met the course standard during his 1st essay, and final exam evaluations.
Any help to get the items to add to an array and to call upon it later would be amazing. ive gotten results close to what i need using python, (user prompts instead of drop down boxes) but JS is just not my strong suit.
Copy link to clipboard
Copied
The problem is this in the last line:
+ this.getField("Var30") +
This is how you access a field, not a variable. Replace it with just:
+ Var30 +
Copy link to clipboard
Copied
Change this line:
var Var1 = this.getField("Test1");
To:
var Var1 = this.getField("Test1").valueAsString;
Copy link to clipboard
Copied
Also, remove all the semi-colons after the if-statements.
Copy link to clipboard
Copied
To combine the values of an array to a single string use the join method, like this:
var Var30 = fexceedArray.join(", ");
Copy link to clipboard
Copied
All solid corrections, i forgot to add the '.valueAsString' when typing it up for this post. All your comments got me a lot closer than i have been yet. Problem still remains though, when using: "var Var30 = fexceedArray.join(", ");"
field box will generate the text finally, but comes out as:
Mr. Rodriguez far exceeded the course standard during his null evaluation.Mr. Rodriguez exceeded the course standard during his null evaluation. Mr. Rodriguez met the course standard during his null evaluation.
Not sure if my issue is adding items to the array or printing it
Copy link to clipboard
Copied
I checked both all of the tests with all three ratings and still comes up with null
Copy link to clipboard
Copied
This happens when the array is empty.
Copy link to clipboard
Copied
Actually, when the array is empty join should return an empty string, not null.
Mike, can you post your (new) full code?
Copy link to clipboard
Copied
var metArray = [];
var exceedArray = [];
var fexceedArray = [];
var Var1 = this.getField("PRT").valueAsString;
if(Var1 == "Met"){
metArray.push("Physical Readiness Training");
}
else if(Var1 == "Exceeded"){
exceedArray.push("Physical Readiness Training");
}
else if(Var1 == "Far Exceeded"){
fexceedArray.push("Physical Readiness Training");
}
var Var2 = this.getField("D/C").valueAsString;
if(Var2 == "Met"){
metArray.push("Conduct Squad Drill");
}
else if(Var1 == "Exceeded"){
exceedArray.push("Conduct Squad Drill");
}
else if(Var1 == "Far Exceeded"){
fexceedArray.push("Conduct Squad Drill");
}
var Var7 = this.getField("540").valueAsString;
var Var8 = "";
if(Var7 == "Yes"){
Var8 = "\n\nSoldier scored 540 points or more on the ACFT with minimum of 80 points in each event and, IAW AR 600–9, is exempt from Army body fat assessment.";
}
else if(Var7 == "No"){
Var8 = "";
}
var Var30 = fexceedArray.join(", ");
var Var20 = exceedArray.join(", ");
var Var10 = metArray.join(", ");
event.value = this.getField("Name").valueAsString + " far exceeded the course standard during their " + this.getField("Var30") + " evaluation. " + this.getField("Name").valueAsString + " exceeded the course standard during their " + this.getField("Var20") + " evaluation. " + this.getField("Name").valueAsString + " met the course standard during their " + this.getField("Var10") + " evaluation. " + Var8 + "\n\nACFT PASSED: " + this.getField("Date9_af_date").valueAsString;
Currently Returns:
SPC Rodriguez far exceeded the course standard during their null evaluation. SPC Rodriguez exceeded the course standard during their null evaluation. SPC Rodriguez met the course standard during their null evaluation.
Soldier scored 540 points or more on the ACFT with minimum of 80 points in each event and, IAW AR 600–9, is exempt from Army body fat assessment.
ACFT PASSED: 20240320
Copy link to clipboard
Copied
The problem is this in the last line:
+ this.getField("Var30") +
This is how you access a field, not a variable. Replace it with just:
+ Var30 +
Copy link to clipboard
Copied
Wow that instantly fixed it. Not sure why i even did that since i didnt do it for the other Variables.
Thank you so much!

