diff --git a/Client-Side Components/Client Scripts/Auto-Populate Short Discription/Auto populate short description.js b/Client-Side Components/Client Scripts/Auto-Populate Short Discription/Auto populate short description.js new file mode 100644 index 0000000000..ab05f00a7c --- /dev/null +++ b/Client-Side Components/Client Scripts/Auto-Populate Short Discription/Auto populate short description.js @@ -0,0 +1,29 @@ +function onChange(control, oldValue, newValue, isLoading, isTemplate) { + if (isLoading || newValue === '') { + return; + } + + // Define category-to-short description mapping + var categoryToShortDescription = { + 'hardware': 'Hardware Issue - ', + 'software': 'Software Issue - ', + 'network': 'Network Issue - ', + 'inquiry': 'Inquiry/Help - ', + 'database': 'Database - ' + }; + + // Convert the selected value to lowercase for matching + var selectedCategory = newValue.toLowerCase(); + + // If category exists in mapping, update the short description + if (categoryToShortDescription.hasOwnProperty(selectedCategory)) { + var existingDesc = g_form.getValue('short_description') || ''; + var prefix = categoryToShortDescription[selectedCategory]; + + // Only add prefix if it's not already there + if (!existingDesc.startsWith(prefix)) { + g_form.setValue('short_description', prefix + existingDesc); + g_form.showFieldMsg('short_description', 'Short Description auto-updated based on category.', 'info'); + } + } +} diff --git a/Client-Side Components/Client Scripts/Auto-Populate Short Discription/Readme.md b/Client-Side Components/Client Scripts/Auto-Populate Short Discription/Readme.md new file mode 100644 index 0000000000..7bf56626d9 --- /dev/null +++ b/Client-Side Components/Client Scripts/Auto-Populate Short Discription/Readme.md @@ -0,0 +1,45 @@ +Auto-Populate Short Description (Client Script) +Overview + +This client script automatically updates the Short Description field in ServiceNow whenever a user selects a category on the form. It improves data consistency, saves time, and ensures that short descriptions remain meaningful and standardized. + +How It Works + +When a user selects a category such as Hardware, Software, or Network, the script automatically prefixes the existing short description with a corresponding label (for example, “Hardware Issue –”). +This makes incident records easier to identify and improves the quality of data entry. + +Configuration Steps + +Log in to your ServiceNow instance with admin or developer access. + +Navigate to System Definition → Client Scripts. + +Create a new Client Script with the following details: + +Table: Incident + +Type: onChange + +Field name: category + +Copy and paste the provided script into the Script field. + +Save the record and make sure the script is active. + +Testing + +Open any existing or new Incident record. + +Select a category such as Hardware or Software. + +The Short Description field will automatically update with the corresponding prefix. + +Benefits + +Speeds up data entry for users. + +Maintains consistency in short descriptions. + +Reduces manual effort and human errors. + +Enhances clarity in incident listings and reports.