Expand my Community achievements bar.

Saving JavaScript Variable

Avatar

Level 2

I have created a form using a floating variable set in LC Scripting Object that should allow a field to update and populate multiple fields throughout my form. When exporting as a Dynamic PDF, these variables do not save with updated information once the form is closed and then re-opened. What currently happens is the form loads the default var values everytime the form is opened. I have changed the Default Scripting savings to "Automatically" in the Default tab in the "Form Properties".

In a final PDF format, would the user be able to update these fields, save, close, and open the form that would contain the udpated data?

Exerpt from my form below:

form1.#subform[0].#variables[0].varTEST - (JavaScript, client)

var Company_Name = "Test Company";

In my SubForm I have a Text Field (SCENCSCompany), with the following codes for "EXIT" and "READY:LAYOUT"

form1.#subform[0].SCENCSCompany::exit - (JavaScript, client)

varTEST.Company_Name = SCENCSCompany.rawValue;

form1.#subform[0].SCENCSCompany::ready:layout - (JavaScript, client)

SCENCSCompany.rawValue = varTEST.Company_Name;


10 Replies

Avatar

Level 2

The second part of my question, is this the most effective way to code what I am trying to do?

This code would be used for a significant number of text fields throughout my form.

Avatar

Level 10

Hi,

A couple of things about variables.

First you have a Form Variable "varTest". You can set/get its value using the .value property (not .rawValue).

this.rawValue = varTest.value;

However in your form you are trying to declare a Script Variable "Company_Name" within the Form Variable. Even if this works, Script Variables are not saved with the form.

Now the for the rest of the script: I would not go down this route. It seems that you want an initial value for SCENCSCompany and that once the user inputs a company name, you want that to appear in all instances of SCENCSCompany. Is that correct?

If so, you could set up a null pattern for the textfield object. Select it and go to the Object > Field palette. There click Patterns and in Allow Null input a default company name or string that you want to inform the user what to do next. See here: http://assure.ly/pAZsjS.

Then if you want the inputted company name to appear in all instances of SCENCSCompany, select it and go to the Object > Binding palette. There select a Global Binding for the object. At runtime the object's instances will display the same data.

I think that is what you are after and if it is, then it can be achieved without script. If not, can you provide more info.

Niall

Avatar

Level 2

Thanks Niall,

Your post was super helpful. I guess my concept of how LC handeld certain JavaScript variables was a little off, but I think I understand now.

The Field Pallette is close to what I want, but different. My form is intended to have a "Internal Only" section that can set certain settings or variables based on a specific applicant, over multiple stages of our process. So many of the data entries would be used multiple times depending on the current stage.

Based on your comments, I will use fields in the "Interal Only" page with a default value, the other fields throughout the process (and other subforms) would have a "readOnly" access and the same global binding (name).

Avatar

Level 2

When I reference the data in JavaScript, would I need to provide the full path to the raw data?

INTERNAL_ONLY.SCENCSCompany.rawValue;

Or is there a shorter way to access the binding values of a field?

Avatar

Level 10

Hi,

Have a look here for a description and example PDF for relative references:

http://assure.ly/kUP02y.

It depends on the distance/separation from the object with script and the

object referenced in the script. The easiest way to reference objects in LC

Designer is the Control+Click method.

³The term ³binding² has a different meaning to you situation (I think). You

are after the object¹s value.

Hope that helps,

Niall

Avatar

Level 2

That sample was super helpful. In my case may need to do a combination of relative and absolute SOM expressions.

For the sake of consistancy, in my form I have 5 pages (page1, page2,...) where a textField (SCENCSCompany) is present on page2 & page3.

If my JavaScript code is on the same page (# 2 &3) I can use a relative expression (SCENCSCompany.rawValue); but on page 1, 4, & 5 I would need to use an absolute expression (page2.SCENCSCompany.rawValue). Correct?

Would it matter what page I reference the textField to since it has a binding of "use global data"?

Avatar

Level 10

If you are using Global Binding in the Object > Binding palette, then you

don¹t need any script at all. The value the user inputs on page 1 will

automatically appear in all other instances of the object with the same

name, irrespective of where on the form the other instances are.

Niall

Avatar

Level 2

Sorry, I was unclear. My form will include JavaScript that will sourcing these textFields in to an outputTextField dependant on a user inuput radio button.

Example

- page2 (SubForm)

- Contact1 (textField that appears on multiple pages with global binding)

- Contact2 (textField that appears on multiple pages with global binding)

- option (radioButton)

- page3 (SubForm)

- displayContact (textField, no global binding)

page3.displayContact::ready:layout

if (page2.option.rawValue == 1) {

     displayContact = page2.Contact1.rawValue;

     } else {

     displayContact = page2.Contact2.rawValue;

}

Would the above JS code be correct for referencing textFields from different subForms with globaly binded data? and since there would be multiple textFields on different subForms would it be best practice to have all the JS code reference one textfield or multiple?

Avatar

Level 10

Hi,

Your script is basically okay, however you are missing the .rawValue off the

displayContent object. One point, the layout:ready event can lead to

performance issues, as it fires everything ANY object changes. Therefore I

would be more inclined to script in the click event of the radio button

exclusion group on page 2:

if (this.rawValue == 1) {

page3.displayContact.rawValue = Contact1.rawValue;

} else {

page3.displayContact.rawValue = Contact2.rawValue;

}

I am out so can¹t look at it in any more detail at the moment.

Niall

Avatar

Level 2

Perfect. I changed the event to the click event of the radio and that worked great; also caught the missing .rawValue.

Thanks again!