Use a custom script to override the default visibility rules for a particular control in
a heritage coach.
About this task
The following procedure illustrates how you can create private
variables to use in a custom visibility script, and how the values
of those variables determines visibility of the selected control.
Procedure
-
Open the service that contains the heritage coach to work with.
- Click the Variables tab and add
the private variables that you need for the custom script. For this
example, add Boolean variables named
visible , enabled ,
and required.
- Click the Coaches tab.
-
Click the heritage coach control for which you want to add visibility control.
- Click the Visibility option in the
properties.
- Click the Override Parent Visibility check
box to enable it. Doing so allows you to change the default visibility
properties.
- From the Default Visibility list,
select the Hidden (no access) for everyone option.
- Click the Custom Script button.
- In the Custom Visibility section,
enter the JavaScript rule to control visibility.
The following
example uses a server-side JavaScript function, and so
return statements
are required. For custom visibility using server-side JavaScript,
return one of the following values (must be in upper case):
Table 1. Values returned for custom visibility
| Value |
Result |
| "NONE" |
Hidden |
| "READ" |
Disabled |
| "FULL" |
Editable |
| "REQUIRED" |
Required |
The following script causes the runtime engine to determine
if user input is required:
var customVisibility;
if(tw.local.visible) {
if(tw.local.enabled) {
if(tw.local.required) {
customVisibility = "REQUIRED";
}
} else {
customVisibility = "READ";
}
} else {
customVisibility = "NONE";
}
return customVisibility;
If user input is not required,
the control can be edited, but it is not required. If the value of
tw.local.visible is
false, the control is not displayed to the user.
- You can set default values for the variables (that you
added in step 2) and then run the service to test the script.