UI Policy vs. Client Script
UI Policy
Definition:
A UI Policy is a configuration tool used to dynamically control the visibility, mandatory status, and read-only status of fields on a form based on certain conditions. UI Policies are declarative and do not require coding knowledge to set up.
Key Features:
- Purpose: Primarily used to manage the user interface elements (fields, sections) on a form based on conditions. For example, making a field mandatory or visible based on the value of another field.
- Execution: UI Policies run on the client-side and can be triggered by form load or field changes.
- Conditions: Define conditions using simple logical expressions to determine when the policy should be applied.
- Actions: You can set fields to be visible, hidden, mandatory, or read-only.
Example Use Case:
You might use a UI Policy to make a "Department" field mandatory if the "Request Type" field is set to "New Hire."
How to Set Up:
- Navigate to System UI > UI Policies.
- Create a new UI Policy and define the conditions under which it should apply.
- Add UI Policy Actions to specify which fields should be affected (e.g., make a field mandatory).
Client Script
Definition:
A Client Script is a script that runs on the client-side (in the user's browser) and is used to control form behavior, validate data, or perform other tasks based on user interactions or form state. Client Scripts require JavaScript coding skills to implement.
Key Features:
- Purpose: Provides more complex and customized interactions compared to UI Policies. You can perform validations, manipulate field values, and respond to user actions programmatically.
- Execution: Client Scripts are triggered by form events such as loading the form, changing a field value, or submitting the form.
- Types: Various types of client scripts include onLoad, onChange, onSubmit, and onCellEdit.
- Flexibility: Offers extensive control and flexibility to perform complex operations or validations.
Example Use Case:
You might use a Client Script to validate that the value entered in a "Start Date" field is not earlier than the current date before allowing the form to be submitted.
How to Set Up:
- Navigate to System Definition > Client Scripts.
- Create a new Client Script and choose the script type (e.g., onLoad, onChange).
- Write JavaScript code to define the behavior you want to implement.
Key Differences
- Complexity:
- UI Policy: Simple, no coding required. Used for basic field visibility, mandatory, and read-only settings.
- Client Script: Requires JavaScript coding. Used for more complex logic and validation.
- Purpose:
- UI Policy: Controls form field behavior based on conditions. Declarative configuration.
- Client Script: Provides programmatic control and validation. Allows for more dynamic and complex interactions.
- Performance:
- UI Policy: Generally better for simple field manipulations with less performance overhead.
- Client Script: More powerful but may impact performance if not optimized, especially for complex scripts.
- Use Cases:
- UI Policy: Ideal for straightforward use cases like showing/hiding fields or making fields mandatory.
- Client Script: Best for scenarios requiring advanced logic, such as validating user input or dynamically modifying field values based on complex conditions.
- Execution:
- UI Policy: Executes in response to form load or field changes with minimal scripting.
- Client Script: Executes based on form events and can include complex scripting.