Skip to content

Commit 2671acf

Browse files
Auto populate short description (#2312)
* Create Auto populate short description * Create Readme.md * Rename Auto populate short description to Auto populate short description.js
1 parent 580f8c5 commit 2671acf

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
if (isLoading || newValue === '') {
3+
return;
4+
}
5+
6+
// Define category-to-short description mapping
7+
var categoryToShortDescription = {
8+
'hardware': 'Hardware Issue - ',
9+
'software': 'Software Issue - ',
10+
'network': 'Network Issue - ',
11+
'inquiry': 'Inquiry/Help - ',
12+
'database': 'Database - '
13+
};
14+
15+
// Convert the selected value to lowercase for matching
16+
var selectedCategory = newValue.toLowerCase();
17+
18+
// If category exists in mapping, update the short description
19+
if (categoryToShortDescription.hasOwnProperty(selectedCategory)) {
20+
var existingDesc = g_form.getValue('short_description') || '';
21+
var prefix = categoryToShortDescription[selectedCategory];
22+
23+
// Only add prefix if it's not already there
24+
if (!existingDesc.startsWith(prefix)) {
25+
g_form.setValue('short_description', prefix + existingDesc);
26+
g_form.showFieldMsg('short_description', 'Short Description auto-updated based on category.', 'info');
27+
}
28+
}
29+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Auto-Populate Short Description (Client Script)
2+
Overview
3+
4+
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.
5+
6+
How It Works
7+
8+
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 –”).
9+
This makes incident records easier to identify and improves the quality of data entry.
10+
11+
Configuration Steps
12+
13+
Log in to your ServiceNow instance with admin or developer access.
14+
15+
Navigate to System Definition → Client Scripts.
16+
17+
Create a new Client Script with the following details:
18+
19+
Table: Incident
20+
21+
Type: onChange
22+
23+
Field name: category
24+
25+
Copy and paste the provided script into the Script field.
26+
27+
Save the record and make sure the script is active.
28+
29+
Testing
30+
31+
Open any existing or new Incident record.
32+
33+
Select a category such as Hardware or Software.
34+
35+
The Short Description field will automatically update with the corresponding prefix.
36+
37+
Benefits
38+
39+
Speeds up data entry for users.
40+
41+
Maintains consistency in short descriptions.
42+
43+
Reduces manual effort and human errors.
44+
45+
Enhances clarity in incident listings and reports.

0 commit comments

Comments
 (0)