forked from ServiceNowDevProgram/code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuto populate short description
More file actions
29 lines (25 loc) · 1.09 KB
/
Auto populate short description
File metadata and controls
29 lines (25 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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');
}
}
}