In ServiceNow, you can dynamically modify the options of a form's select box based on specific conditions, such as the user's location. For your requirement, where you want to remove an option from a select box based on the user's location, you can leverage Client Scripts to achieve this.
This example provides a basic implementation of how to remove options from a select box based on the user's location. Remember to adjust the field names (caller_id, user_location, your_select_box_field) and the specific values (Location A, etc.) according to your instance's configuration.
Example: Client Script (Type: onChange)
When the location of the user in the caller reference field changes, this script checks the user's location and accordingly removes the specific option from your select box field.
- Navigate to: System Definition > Client Scripts
- Click on: New
- Fill the form:
- Name: Enter a meaningful name for the script
- Table: Incident (or the table you are modifying)
- Type: onChange
- Field name: caller_id (assuming this field will trigger the change)
- Script: Enter the following JavaScript (Make sure to customize this script as per your actual field names and values):
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
// Assuming 'location' is the field in the user's record holding their location and 'your_select_box_field' is the target select box.
if (newValue) {
var userGR = new GlideRecord('sys_user'); // Adjust 'sys_user' if your user table has a different name or sys_id needs to be queried from another table.
userGR.get(newValue); // Here, newValue is the sys_id of the selected caller
if (userGR.location == 'sys_id_of_Location_A') { // Replace 'sys_id_of_Location_A' with the actual sys_id of Location A.
// Now remove the option from the select box
var selectBox = g_form.getGlideUIElement('your_select_box_field'); // replace 'your_select_box_field' with the actual field name
if (selectBox) {
selectBox.removeOption('value_of_option_A'); // Replace 'value_of_option_A' with the value of the option you want to remove
}
}
}
}
-
Condition: Enter any conditions if required (or leave it to default to run whenever the specified field changes).
-
Click: Submit
Important Notes:
- Replace
your_select_box_field with the actual name of your select box field.
- The script uses
sys_id and other field names as placeholders. Ensure you accurately replace these with actual sys_ids and field names from your ServiceNow instance.
- If the user's location isn't directly accessible via
userGR.location, you might need to adjust the script accordingly to navigate through related records.
- Testing in a sub-production instance before applying changes to the production instance is always recommended.
This script is intended to provide a starting point. Depending on the complexity and specifics of your ServiceNow setup, it may require adjustments.