Mandatory fields cannot be hidden using setVisible() or setDisplay() in client scriptsDescription When attempting to use setVisible() or setDisplay() methods in a client script to hide a field that has been set as mandatory using setMandatory(), the visibility methods do not work as expected. The field remains visible even though the visibility method was called. Steps to Reproduce Starting from the Istanbul release, ServiceNow intentionally blocks the use of setVisible() or setDisplay() on mandatory fields in client scripts. This is a designed behavior to prevent issues where a field is marked as mandatory but is hidden, making it impossible for users to complete the required field. Open a record on the target tableTrigger the condition that should change field visibility and mandatory statusVerify the field shows/hides as expectedVerify the mandatory indicator (red asterisk) appears/disappears as expectedTest form submission to ensure mandatory validation works correctly when the field is visible Related Problem: PRB1284668WorkaroundTo control both visibility and mandatory behavior on the same field, you must use one of the following supported approaches instead of combining these methods in a single client script. Option 1: Use UI Policies (Recommended) UI Policies are the preferred method for controlling field visibility and mandatory behavior together. They offer better performance, maintainability, and execution reliability compared to client scripts. Steps to create a UI Policy Navigate to System UI > UI PoliciesClick New to create a new UI PolicyFill in the following fields: Table: Select the table where the field exists (e.g., Incident, Change Request)Short description: Provide a meaningful description (e.g., "Hide and make priority non-mandatory based on urgency")Active: Check this boxConditions: Define when this policy should apply (e.g., Urgency is 3 - Low) Click Submit to save the UI PolicyIn the UI Policy Actions related list at the bottom, click NewConfigure the UI Policy Action: Field name: Select the field you want to controlMandatory: Uncheck to make the field non-mandatory (or check to make it mandatory)Visible: Uncheck to hide the field (or check to show it) Click Submit to save the actionTest the UI Policy by opening a record on the target table and verifying the field behavior matches your conditions Note: UI Policies execute automatically when conditions are met and do not require custom scripting. Reference: Use UI Policies instead of Client Scripts Option 2: Use Separate Client Scripts If UI Policies do not meet your specific requirements (e.g., you need complex custom logic), you can use two separate client scripts with controlled execution order. Steps to implement separate client scripts Navigate to System Definition > Client ScriptsClick New to create the first client script for mandatory behaviorConfigure the first client script: Name: Provide a descriptive name (e.g., "Set priority mandatory")Table: Select your target tableType: Choose appropriate type (e.g., onChange, onLoad)Order: Set to 100 (this script will execute first)Script: Add your setMandatory() logic Example script for mandatory behavior: function onChange(control, oldValue, newValue, isLoading) { if (newValue == '1') { // Example condition g_form.setMandatory('priority', true); } else { g_form.setMandatory('priority', false); } } Click Submit to save the first client scriptClick New again to create the second client script for visibilityConfigure the second client script: Name: Provide a descriptive name (e.g., "Control priority visibility")Table: Select the same target tableType: Choose the same type as the first scriptOrder: Set to 200 (this script will execute second, after mandatory is set)Script: Add your setVisible() or setDisplay() logic Example script for visibility: function onChange(control, oldValue, newValue, isLoading) { if (newValue == '1') { // Example condition g_form.setDisplay('priority', true); } else { g_form.setDisplay('priority', false); } } Click Submit to save the second client scriptTest by opening a record and verifying that: The mandatory behavior applies correctlyThe visibility changes occur after mandatory state is setNo conflicts occur between the two scripts Important: The Order field determines execution sequence. Lower numbers execute first. Ensure the setMandatory() script has a lower order value than the setVisible()/setDisplay() script. Best Practice Do not use setMandatory() and setVisible() or setDisplay() together in the same client script. This combination is blocked by the platform and will not work as expected. Verification After implementing either workaround, verify the solution works correctly: Open a record on the target tableTrigger the condition that should change field visibility and mandatory statusVerify the field shows/hides as expectedVerify the mandatory indicator (red asterisk) appears/disappears as expectedTest form submission to ensure mandatory validation works correctly when the field is visibleRelated Problem: PRB1284668