PDA

View Full Version : Set a Field Value based on other Field Values


David Miller
November 22nd, 2011, 08:05 PM
Is is possible to set a value for "Field X" based on user-choices for "Field Y" plus "Field Z" using JavaScript rules?

Understand how to write a JavaScript rule that would return a specific value based on on multiple user-field values. But, want to set an "actual" field value.

For Example:

if ((Field("Field Y") == "A") && (Field("Field Z") == "B"))
return 'A' + '_' + 'B'; //CAN --FIELD X-- BE SET TO THIS VALUE? -- NOT POSSIBLE? -- DON"T THINK SO--//

The goal is to set a "hidden" iForms field value based on multiple user-field choices.

It would be great to be able to do this via JavaScript rules. Not sure if it is possible.

Thank you,
-Dave

step
November 23rd, 2011, 07:58 AM
Just trying to make sure I understand what you're trying to achieve: are you wanting to change the value of "Field X" to "A_B" given "Field Y" is "A" and "Field Z" is "B"? Or are you trying to change the value of "Field X" to whatever the value of "Field Y" and "Field Z" are, respectively, separating them by an underscore?

I don't think that you can physically change the value of a field in your data. You could, however map the value of the two fields to a variable and return that instead:


var FieldX = "";

if (Field("Field Y") == "A" && Field("Field Z")){
FieldX = "A_B";
}
return FieldX;

David Miller
November 23rd, 2011, 09:00 AM
Hi Step,

You said, "...I don't think that you can physically change the value of a field in your data..." That is exactly what I was trying to ask.

Didn't think so either. Thank you for confirming.

Dan Korn
November 23rd, 2011, 12:24 PM
Is is possible to set a value for "Field X" based on user-choices for "Field Y" plus "Field Z" using JavaScript rules?

Understand how to write a JavaScript rule that would return a specific value based on on multiple user-field values. But, want to set an "actual" field value.

For Example:

if ((Field("Field Y") == "A") && (Field("Field Z") == "B"))
return 'A' + '_' + 'B'; //CAN --FIELD X-- BE SET TO THIS VALUE? -- NOT POSSIBLE? -- DON"T THINK SO--//

The goal is to set a "hidden" iForms field value based on multiple user-field choices.

It would be great to be able to do this via JavaScript rules. Not sure if it is possible.

Thank you,
-Dave
If you name your rule "Field X", then whatever value it returned from that rule will be used for the "Field X" variable in your variable text frames, effectively overriding the value of any actual data field with the same name. Is that what you mean?

David Miller
November 23rd, 2011, 12:35 PM
Yes. That is exactly what I mean. I will give it a try. Thank you.

step
November 28th, 2011, 08:48 AM
If you name your rule "Field X", then whatever value it returned from that rule will be used for the "Field X" variable in your variable text frames, effectively overriding the value of any actual data field with the same name.

Right, but that's essentially the same as returning it as a global variable right? It's not going to actually rewrite the data file – if that's the intended goal.

Dan Korn
November 28th, 2011, 09:58 AM
Right, but that's essentially the same as returning it as a global variable right?
No. A "global variable" implies a JavaScript variable, which can be accessed in a JavaScript rule, not a FusionPro text variable, which can be accessed directly in a text frame. These are two completely different things.

Creating a rule with the same name as a data field does override the value of the data field when called out in a text frame (which creates a <variable name="***"> tag). However, calls to the JavaScript function Field() will always return the original data field value, and setting a global variable, or creating a rule, doesn't change this. But you can call the RuleOrField() function instead of Field() to apply any rule overrides in other rules. Or, if you do create a global variable, you can also reference that from other rules instead of calling Field().
It's not going to actually rewrite the data file if that's the intended goal.
Nothing described here actually rewrites the data file. The data file is an input file, by definition, so FusionPro doesn't modify it. But you don't want that anyway; you merely want to change how FusionPro handles the data in that file.