Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problems with searching 60 Fields for String and entering the number 10 into a "BSSB" field; No errors

New Here ,
Oct 24, 2016 Oct 24, 2016

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);

}

TOPICS
Acrobat SDK and JavaScript
888
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 25, 2016 Oct 25, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 25, 2016 Oct 25, 2016

break; removed the second valueAsString, does not work yet

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2016 Oct 26, 2016

So what are the results?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 26, 2016 Oct 26, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2016 Oct 26, 2016

Are you sure the value of that field is exactly "Marksmanship"?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 26, 2016 Oct 26, 2016

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;}

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 26, 2016 Oct 26, 2016

I could try to see the i with the alert

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2016 Oct 26, 2016

You should add an alert that shows the value of CSkStringValue...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 26, 2016 Oct 26, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 26, 2016 Oct 26, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 26, 2016 Oct 26, 2016

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;}

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 26, 2016 Oct 26, 2016
LATEST

Yea, you are right, deleted 3 fields that were not needed, thanks, off to the Dentist for a root canal. yea

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines