Copy link to clipboard
Copied
Problems with searching 60 Fields for String and entering the number 10 into a "BSSB" field; No errors
function SetBSMarksmanshipFieldValues() { for (var i = 1; i<61; i++) { var CSki = ("CSk" + ); var CSkStringValue = this.getField(CSki).valueAsString; if (CSkStringValue.valueAsString == "Marksmanship") { this.getField("BSSB").value = 10; i = 60;}}}
if(event.willCommit){if(event.value == "") this.resetForm (["BSSB"]);
else SetBSMarksmanshipFieldValues(event.value);
}
Copy link to clipboard
Copied
There are at least two issues with your function. I'll post the code again in a more formatted way, so it's easier to refer to specific lines in it:
function SetBSMarksmanshipFieldValues() {
for (var i = 1; i<61; i++) {
var CSki = ("CSk" + );
var CSkStringValue = this.getField(CSki).valueAsString;
if (CSkStringValue.valueAsString == "Marksmanship")
{ this.getField("BSSB").value = 10; i = 60;}
}
}
Line 6: Minor issue. That is not a good way of breaking out of a loop. Use the "break" command instead.
Line 5: Major issue: You've already defined CSkStringValue as the string value of the field, so there's no need to access this property once more.
Copy link to clipboard
Copied
break; removed the second valueAsString, does not work yet
Copy link to clipboard
Copied
So what are the results?
Copy link to clipboard
Copied
function SetBSMarksmanshipFieldValues() {
for (var i = 1; i<61; i++) {
var CSki = ("CSk" + );
var CSkStringValue = this.getField(CSki).valueAsString;
if (CSkStringValue == "Marksmanship")
{ this.getField("BSSB").value = 10; break;}
}
}
no errors but the "BSSB" field does not equal 10, yet
Copy link to clipboard
Copied
Are you sure the value of that field is exactly "Marksmanship"?
Copy link to clipboard
Copied
Marksmanship is in the dropdown list
I added this to make sure the function starts
app.alert("We are in the Marksmanship Function", 3);
and it does
function SetBSMarksmanshipFieldValues() {
app.alert("We are in the Marksmanship Function", 3);
for (var i = 1; i<61; i++) {
var CSki = ("CSk" + );
var CSkStringValue = this.getField(CSki).valueAsString;
if (CSkStringValue == "Marksmanship")
{ this.getField("BSSB").value = 10; break;}
}
}
Copy link to clipboard
Copied
I could try to see the i with the alert
Copy link to clipboard
Copied
You should add an alert that shows the value of CSkStringValue...
Copy link to clipboard
Copied
function SetBSMarksmanshipFieldValues() {
for (var i = 1; i<61; i++) {
var CSki = ("CSk" + );
app.alert("We are in the Marksmanship Function " + CSki, 3);
var CSkStringValue = this.getField(CSki).valueAsString;
if (CSkStringValue == "Marksmanship")
{ this.getField("BSSB").value = 10; break;}
}
}
BSSB = 10 now, but had errors before the app.alert started the count and after
TypeError: f is null
1051:byteCodeToolException in line 1051 of function AFSimple_Calculate, script byteCodeTool
Copy link to clipboard
Copied
That means there's an error in the calculation script of some other field,
most likely because you renamed or deleted a field that you used in the
calculation.
Copy link to clipboard
Copied
added line to get the BSSB before the loop
BSSBvalue = 0
CSkStringValue = Marksmanship
TypeError: f is null
1051:byteCodeToolException in line 1051 of function AFSimple_Calculate, script byteCodeTool
function SetBSMarksmanshipFieldValues() {
var BSSBvalue = this.getField("BSSB").value;
app.alert("We are in the Marksmanship Function " + BSSBvalue, 3);
for (var i = 1; i<61; i++) {
var CSki = ("CSk" + );
var CSkStringValue = this.getField(CSki).valueAsString;
app.alert("We are in the Marksmanship Function " + CSkStringValue, 3);
if (CSkStringValue == "Marksmanship")
{ this.getField("BSSB").value = BSSBvalue + 10; break;}
else { this.getField("BSSB").value = 0; break;}
}
}
Copy link to clipboard
Copied
Yea, you are right, deleted 3 fields that were not needed, thanks, off to the Dentist for a root canal. yea
Find more inspiration, events, and resources on the new Adobe Community
Explore Now