Hide a Field in One App¶
A scanning operator in Web Capture does not need the InternalNotes field, but indexers in the Index app do. One content type serves both, so the field must hide in some apps and show in others.
At a glance
- Extension point Custom Index Behavior
- You need A field to hide (
InternalNoteshere, any type that allows Custom Behaviors); permission to edit content types in the Connections app - Teaches
context.app, and a behavior that acts on panel load
Set it up¶
- In the Connections app, open the content type and select
InternalNotes. - Open Behaviors > Add a Behavior > Custom Behavior.
- Name it
Hide in capture apps, paste the script below, and select Save & Close.
The panel load runs every behavior, so the script runs as soon as the panel opens. No change event is needed.
Script¶
Custom Behavior on InternalNotes
// Attach to: InternalNotes
// Reads: context.app. Writes: visibility of InternalNotes.
var hideIn = ["webcapture", "upload", "addins"];
builder.SetIsVisible(hideIn.indexOf(context.app) === -1);
How it works¶
context.appnames the app that shows the panel, in lowercase. The full list is in the Reference.SetIsVisibleacts on the attached field, so the script needs no field name.- The script shows the field in every app that is not in the list, including apps added later.
- On the server
context.appis"worker". The field is "shown" there, which has no effect because there is no screen.
Test it¶
- Save the behavior.
- Open a document of this content type in Web Capture.
InternalNotesis hidden. - Open a document in the Index app.
InternalNotesshows.
You are done when the field is hidden in Web Capture, Upload and the add-ins, and shows in the Index, View and QC apps.
The Test button in the editor runs with context.app set to taxonomy, so the field shows there.
What can go wrong¶
Watch out
- The field hides everywhere, or nowhere. An app name has a capital letter or a typo. Write
context.appinto a text field once to see the exact value. - A required field blocks the user. A Required behavior still applies to a hidden field. Do not hide a required field in an app where the user must submit.
- Hiding is not access control. The value is still on the document and visible through other apps and the API.
Variations¶
Show the field only in some apps: builder.SetIsVisible(["webindex", "qc"].indexOf(context.app) !== -1);. To make it read-only instead of hidden, use builder.SetIsEnabled(...) with the same test.