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

Global Variables and Dropdowns

Participant ,
Jun 06, 2016 Jun 06, 2016

Hello,

I've been experimenting with Global Variables and Dropdowns as a way to save the value set in a dropdown after a page has been deleted so that when a copy is re-spawned I can draw the value in the dropdown directly from the global variable rather than a very long switch statement.

So the theory is this;

First a page is spawned from a hidden template, using a button on the initial page, lets call this the "Master Page" and the spawned page the "Copy Page" the user selects a few options from many choices and then when finished closes the Copy Page.

Those options then change certain values on the Master Page.

However the user may decide they wish for different options and so re-spawn the Copy Page once again.

Of course I don't want them to have to fill out all the details all over again and so values are autofilled on the Copy Page from hidden fields on the Master Page.

This works fine except for one specific case being a dropdown box. Due to another stage in the process the hidden text fields, when printed, will show up on the Master Page. So because of this the text field value is different to the value of the dropdown and this is where the global variable comes in.

Before the Copy Page is deleted I have a function setting the value of the global variable to that of the dropdown, so when the page is spawned again it can pull the dropdown value from the global variable saving me the leg work of writing a switch statement with 30 or so outcomes.

Hopefully that explains the theory.

Everything is working to plan except when the Copy Page is re-spawned, I get an error message in the debugger stating;

InvalidSetError: Set not possible, invalid or unknown.

Field.value:30:Field CreateABarLayout:Mouse Up

Here is how the code looks;

Document Level

//Taking the value of the dropdown and putting it in the global variable

function ObscureType(ChkObsc, ObscDp, IcnObsc, GlobalObscVar, ObscTxt,

ValueObsc, ValueClear) {

     var fldChkObsc = this.getField(ChkObsc).value;

     var fldObscDp = this.getField(ObscDp);

     var fldIcnObsc = this.getField(IcnObsc);

     var fldObscTxt = this.getField(ObscTxt);

     if (fldChkObsc == "Yes") {

     GlobalObscVar = fldObscDp.value; //Setting the global variable's value as the dropdown value

     fldIcnObsc.display = display.visible;

     fldObscTxt.value = ValueObsc + GlobalObscVar; /*Here I set the value inside the text field using

the value in the global variable*/

     }

     else {

     fldIcnObsc.display = display.hidden;

     fldObscTxt.value = ValueClear;

     }

}

Here is how I call that function

Inside a button

ObscureType(prefix + "TopObsc",prefix + "TopObscDp", "ObscTop", gblVarTObscVal,

"TopObscTxt", "Top Obscure: ", "Top Clear"); //"prefix" is defined elsewhere on the page

Document Level

//Taking the value of the Global Variable and putting it into the Dropdown

function PullObscType(Global, ObscTxt, ChkObsc, ObscDp, IcnObsc, Value) {

     var fldObscTxt = this.getField(ObscTxt).value;

     var fldChkObsc = this.getField(ChkObsc);

     var fldObscDp = this.getField(ObscDp);

     var fldIcnObsc = this.getField(IcnObsc);

     if (fldObscTxt !== Value) {

     fldChkObsc.value = "Yes";

     fldObscDp.display = display.visible;

     fldObscDp.value = Global; //This is line 30 (There is another function above this which is unrelated)

     fldIcnObsc.display = display.visible;

     }

     else {

     fldChkObsc.value = "Off";

     fldObscDp.display = display.hidden;

     fldObscDp.value = " ";

     fldIcnObsc.display = display.hidden;

     }

}

Here is how I call this function

Inside a button

PullObscType(gblVarTObscVal, "TopObscTxt", "TopObsc", "TopObscDp", "TopObscGlass",

"Top Clear"); /*because of how "prefix" works I am setting these values

on the template page before spawning the copy*/

If needed I can post a link to the document and provide instructions how to re-create the issue.

I believe the issue resides with the line fldObscDp.value = Global; as that is the only line 30 part of the code which is related to the issue.

Another thing I have noticed is that after the ObscureType function is called I am using this line of code;

app.alert(gblVarTObscVal + "-" + gblVarBObscVal);

To see what the values are of both the global variables, gblVarBObscVal comes up empty which is correct however gblVarTObscVal comes up empty aswell even though the text field comes up with the value "Top Obscure: (Correct Dropdown Value)" which is correct.

Sorry if this makes no sense but it's quite a long workflow and I've been trying to figure out what I'm doing wrong for a few days.

Any help is much appreciated

Thank you in advance.

TOPICS
Acrobat SDK and JavaScript , Windows
640
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 ,
Jun 06, 2016 Jun 06, 2016

What's the value of the Global variable at this point?

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
Participant ,
Jun 07, 2016 Jun 07, 2016

After the first set of code it should be whatever was in the dropdown, so if "Arctic" was selected it should be Arctic.

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 ,
Jun 07, 2016 Jun 07, 2016

You should double-check that that's indeed the case. I would also recommend renaming it to something a bit less generic.

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
Participant ,
Jun 07, 2016 Jun 07, 2016

That the thing, I know it must have been correct at some point as the text field does display the correct value when it pulls from the global variable  (fldObscTxt.value = ValueObsc + GlobalObscVar;) So I was wondering if the name was the part causing it to go a little odd but also because the Dropdown gets deleted would that in effect cause the global variable reset to it's default value of ""?

Edit: Okay by adding app.alerts that pull the global variable's value at every stage of the process it does indeed have the correct value when pulling the value into the text field, however after the function has ended, or, when the page is deleted the global variable returns to the value "".

Edit2: For now I've added a hidden text field that takes the value and stores it as it seems to be a more stable way to store it, however I'd still like to use a Global Variable as I am going to start running out of space on pages with hidden fields and such.

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 ,
Jun 07, 2016 Jun 07, 2016

No, that shouldn't matter. The variable is not "bound" to the field, if it

indeed holds just its value and not a reference to the field object itself.

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
LEGEND ,
Jun 07, 2016 Jun 07, 2016

Edit2: For now I've added a hidden text field that takes the value and stores it as it seems to be a more stable way to store it, however I'd still like to use a Global Variable as I am going to start running out of space on pages with hidden fields and such.

If you don't want to add the hidden fields to a visible page, you can add them to a page that you make a template, and then hide the template page.

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
Participant ,
Jun 08, 2016 Jun 08, 2016
LATEST

I was thinking about that but the problem is that the Master Page is also a template in which spawns new copies so, everything has to be, in a sense, modular and self contained.

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