Expand my Community achievements bar.

SOLVED

Calling on variable or conditional format?

Avatar

Level 2

I'm working on a form that creates a wide range of conditional statements that build from one another over time. To do this, I made a single large table with a range of user-filled options. For the problem cell, I've got a set of if-else statements with five potential outcomes, which are themselves dependent upon another variable from a prior cell. The conditional is as follows:

var StW2;

if(GeneralTable.Row1.CollarType.rawValue == "Option 1" && Ero == 1 && RDB46BPF.rawValue >= 96.75 && RDB46BPF.rawValue <= 108.75)

   {StW2 = 0}

   else if(GeneralTable.Row1.CollarType.rawValue == "Option 2" && Ero == 1 && RDB46BPF.rawValue >= 83 && RDB46BPF.rawValue <= 96.75)

   {StW2 = 1}

   else if(GeneralTable.Row1.CollarType.rawValue == "Option 3" && Ero == 1 && RDB46BPF.rawValue < 83 && RDB46BPF.rawValue > 60.75)

   {StW2 = 2}

   else if(GeneralTable.Row1.CollarType.rawValue == "Option 4" && (Ero == 1 && RDB46BPF.rawValue < 60.75) || (Ero == 0 && this.rawValue > 22))

   {StW2 = 3}

   else{StW2 = 4;};

As a test to validate the statement is working, I add this just below the statement so that I can see what StW2's value is in action:

xfa.resolveNode("Row2[9].RDB46CPF").rawValue = StW2;

I've not been able to get any value at all, which must mean there's something wrong with my overall conditional formula, but after several hours of testing and making minute changes and testing again and reviewing these forums, I can't figure out what I'm doing wrong.

A few things of note:

  • Options 1 - 4 of GeneralTable.Row1.CollarType come from a drop-down list users must choose from before they're even allowed to see the table. This function works as designed and there is no chance one of the options won't be selected.
  • Ero is a variable defined in an earlier cell which can only be one of two values based on user input: 0 or 1 ("Pass" or "Fail", respectively).
  • The conditional is located in the exit event of a drop-down box, the contents of which change significantly depending upon which of Options 1 - 4 are selected at the start of the form.
  • RDB46BPF is a cell that contains the results of an earlier formula in the same drop-down box's exit event. This earlier formula has already been tested and works fine.

At the moment I can only think of two possibilities: either there's something wrong with the AND and OR statements' formatting for Option 4, or the cell is not pulling the value of Ero because it was created and defined in a separate cell. If anyone has any insights that might help me out, I'd appreciate it.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Okay, I'll try to make it simple for you to understand...

First of all, to assign a value to a text field you must use the '=' operator as follows :

To compare values you must use the '==' or '===' operators, both have different behaviour but '==' is the most commonly used.

Now to assign a value to a text field, you must use the rawValue property and the '=' operator and to pull the value from the text field use the rawValue property as well.

So technically in the event which you declare the variable Ero, you should assign the value Ero within the text field.

Once you want to access that value from another event, just make sure to use the right reference syntax to access that text field you have assigned the value in, and pull the value using rawValue property... You can also re-declare the variable Ero in that other event directly to be the rawValue of the hidden text field. See example below :

I hope this will help you to get on the right track.

View solution in original post

6 Replies

Avatar

Level 10

Hi there,

Without going any further, if Ero is declared somewhere else than the event itself, you found your problem.

Either you have a hidden field that can hold that value for other events or you create that variable within a script object and create a get set function.

If this does not work, then you probably have something else to fix.

Hope this will help.

Avatar

Level 2

Hey, Magus, thanks for the help. After reading up on the topic of Get Set functions and Script Objects and doing some experimentation, I'm afraid I'm still no closer to a solution. This is almost certainly because I don't understand get how to call upon and change the object value using a get/set function.

I suppose I don't have to use variables to do the intended work, but I would like to learn them anyway to expand upon my LiveCycle knowledge. Is there somewhere I can go to get an in-detail example/ lesson on how to get and change script object variable values through JavaScript at any place in the form I need?

Avatar

Level 10

In this case it would be simpler to store your value in a hidden textfield.

Either one or the other is good, get set functions are only easy access troughout the whole form and might be of a better use when having many different variables to handle. Usually get set functions are for oriented objects... which is not your case. It was only an option.

Go for the hidden text field, sorry for the confusion.

Avatar

Level 2

Apologies, but I remain confused. While I can make a hidden text field easily enough and create variables within it, the primary problem remains: I don't know how to pull the variable values from that hidden text field (or a script object if I were to use that option) for use/changing in other fields. I had hoped it would be as simple as using "==" and "=" comparisons, but clearly that is not the case, and my help files only refer to variables in terms of script objects (and then without telling me how to use them as I intend to).

Please understand, I'm not the most deeply versed in LiveCycle or Javascript. The most knowledge I have regarding variables is how to declare them and use them within a single event. I've scoured a range of sources trying to find out how this works and have come up empty. Apparently it's supposed to be so simple that nobody's bothered to describe the process. Or I just don't know where to look.

Avatar

Correct answer by
Level 10

Okay, I'll try to make it simple for you to understand...

First of all, to assign a value to a text field you must use the '=' operator as follows :

To compare values you must use the '==' or '===' operators, both have different behaviour but '==' is the most commonly used.

Now to assign a value to a text field, you must use the rawValue property and the '=' operator and to pull the value from the text field use the rawValue property as well.

So technically in the event which you declare the variable Ero, you should assign the value Ero within the text field.

Once you want to access that value from another event, just make sure to use the right reference syntax to access that text field you have assigned the value in, and pull the value using rawValue property... You can also re-declare the variable Ero in that other event directly to be the rawValue of the hidden text field. See example below :

I hope this will help you to get on the right track.

Avatar

Level 2

Oh... OH. All this time I was trying to get the script-defined variables! I had no idea we were talking about pulling rawValues. I do that all the time and it should have been obvious.

On the one hand, this does fly in the face of the original reason I was doing all of this in the first place. That original intention was to create a set of formulae based on variables instead of pulling the long codes of rawValues, hopefully making it easier to follow for whoever comes after me in three or four years to update the form. This method pulls the rawValues, which is exactly what I was trying to avoid.

But if it works, it works. I will make use of this method. Thanks, this solves the problem in its entirety!