Skip to main content
Inspiring
June 6, 2016
Question

Global Variables and Dropdowns

  • June 6, 2016
  • 1 reply
  • 790 views

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.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
June 6, 2016

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

Inspiring
June 7, 2016

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

try67
Community Expert
Community Expert
June 7, 2016

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