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

The Proper Way of Using the Global Varibale

Enthusiast ,
Apr 27, 2018 Apr 27, 2018

Copy link to clipboard

Copied

Hi Experts..

its my first time to deal with the Global Object inside the Acro Form, because its also the first time to work with 2 pages in form not only 1

so i noticed that  calculations in the page 2 not working..the code is here , is just Text Field Formatted as Percentage Number that will show the Amount of Check Boxes (if Checked by the user) as Percentage..

I write the following code in (Custom Calculation Script) inside 16 (Text Field with the Same Kind) in every pages of the two,  because every one of percentage is responsible for monitoring 20 Check box Group in one row repeated in 16 row (as Shown in the Loop), this code was working fine until i add the second page, its still working in page 1 of the form but it stopped working in page 2

CallPeriod();

// Initialize counter variable

var sum = 0;

// Loop through the fields

for (var i = 1; i<=20;i++) {

// Add one if check box is not Off

    if (getField("A" + i).value !== "Off") {sum += 1;}

}

// Set this field's value to the sum

var SumFinal = (sum / PeriodNumber.value);

event.value = SumFinal > 1 ? 1 : SumFinal ;

i figure out that the main problem in page 2 that it not receiving the correct local variable (PerionNumber,value) , this Variable was previously called from other Text field under Custom Calculation Script in page one with the script - this was working well when the form was One page

var PeriodNumber =this.getField("PeriodVar");

I  Tried to fix the Problem and Create the Call Period Function (Document Java Script) that Supposed to be the new Solution of the Global Variables and Call this function from (Page Open JavaScript) from the two pages, Because i dont know what is the right way to call it!, also i call this function inside the custom calculation script show above, here is the script

function CallPeriod()

{

global.PeriodNumber =this.getField("PeriodVar");

}

now my question simply what the logical error i miss! that not letting the two pages read the correct value from the global variable, or how to do this in the right way, i read the JS API docs and Some articles but when i see the examples it wasnt match my problem and also maybe i miss understand, any help will be Appreciated  and Thanks in Advance.

Best
Mohammad Hasanin
TOPICS
Acrobat SDK and JavaScript , Windows

Views

506

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Apr 27, 2018 Apr 27, 2018

You don't need to use a global variable.

Simply acquire the field value when you need it.

For example, here is the modified line of code from your post:

var SumFinal = (sum / this.getField("PeriodVar").value); 

You should also learn to debug with the console window, there's a tutorial on it here:

Free Video Content & Full Listing of Available Videos

Votes

Translate

Translate
Community Expert ,
Apr 27, 2018 Apr 27, 2018

Copy link to clipboard

Copied

You don't need to use a global variable.

Simply acquire the field value when you need it.

For example, here is the modified line of code from your post:

var SumFinal = (sum / this.getField("PeriodVar").value); 

You should also learn to debug with the console window, there's a tutorial on it here:

Free Video Content & Full Listing of Available Videos

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Enthusiast ,
Apr 27, 2018 Apr 27, 2018

Copy link to clipboard

Copied

LATEST

Thank you

Best
Mohammad Hasanin

Votes

Translate

Translate

Report

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