Skip to content

Commit f05860a

Browse files
authored
Created a new code snippet for a client script (ServiceNowDevProgram#719)
This code snippet can enhance the user experience in ServiceNow by automatically populating the 'Short Description' field when a user selects a category for an incident or request.
1 parent 1db5eeb commit f05860a

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Client Script to Auto-Populate Short Description based on Category
2+
3+
function onChangeCategory() {
4+
var categoryField = g_form.getValue('category'); // Get the selected category
5+
var shortDescriptionField = g_form.getValue('short_description'); // Get the Short Description field
6+
7+
// Define mappings for categories and corresponding short descriptions
8+
var categoryToShortDescription = {
9+
'Hardware': 'Hardware Issue - ',
10+
'Software': 'Software Issue - ',
11+
'Network': 'Network Issue - ',
12+
'Other': 'Other Issue - '
13+
};
14+
15+
// Update Short Description based on the selected category
16+
if (categoryToShortDescription.hasOwnProperty(categoryField)) {
17+
var newShortDescription = categoryToShortDescription[categoryField] + shortDescriptionField;
18+
g_form.setValue('short_description', newShortDescription);
19+
}
20+
}
21+
22+
// Attach the onChangeCategory function to the 'category' field
23+
g_form.observe('change', 'category', onChangeCategory);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
# Auto-Populate Short Description Client Script
3+
4+
## Overview
5+
6+
This client script is designed to enhance the user experience in ServiceNow by automatically populating the 'Short Description' field when a user selects a category for an incident or request. It simplifies the data entry process, ensures consistency in short descriptions, and saves time for users.
7+
8+
## How It Works
9+
10+
When a user selects a category from the provided options, the script appends a predefined prefix to the existing 'Short Description' value, creating a more informative short description.
11+
12+
### Configuration
13+
14+
To configure and use this client script in your ServiceNow instance, follow these steps:
15+
16+
1. **Create a Client Script:**
17+
18+
- Log in to your ServiceNow instance as an admin or developer.
19+
- Navigate to "System Definition" > "Client Scripts."
20+
- Create a new client script and give it a name (e.g., "Auto-Populate Short Description").
21+
22+
2. **Copy and Paste the Script:**
23+
24+
- Copy the JavaScript code provided in this README.
25+
- Paste the code into your newly created client script.
26+
27+
3. **Attach to 'category' Field:**
28+
29+
- Save the client script and ensure it's active.
30+
- Attach the client script to the 'category' field of the relevant table (e.g., Incident, Request) where you want to enable this functionality.
31+
32+
4. **Define Your Category-to-Short-Description Mappings:**
33+
34+
- Modify the script to define your own mappings for categories and their corresponding short description prefixes. Customize the `categoryToShortDescription` object to match your requirements.
35+
36+
5. **Testing:**
37+
38+
- Test the functionality by creating or editing an incident or request record.
39+
- Select a category, and observe how the 'Short Description' field is automatically populated based on your mappings.
40+
41+
## Example Mapping
42+
43+
Here's an example of how you can define category-to-short-description mappings in the script:
44+
45+
```javascript
46+
var categoryToShortDescription = {
47+
'Hardware': 'Hardware Issue - ',
48+
'Software': 'Software Issue - ',
49+
'Network': 'Network Issue - ',
50+
'Other': 'Other Issue - '
51+
};
52+
```
53+
54+
You can customize these mappings to align with your organization's specific categories and short description conventions.
55+
56+
## Benefits
57+
58+
- Streamlines data entry for users.
59+
- Ensures consistent and informative short descriptions.
60+
- Saves time and reduces the risk of human error.
61+
- Enhances user experience in ServiceNow.

0 commit comments

Comments
 (0)