Jump to content

Set a Field Value based on other Field Values


David Miller

Recommended Posts

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

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...