|
| 1 | +function onChange(control, oldValue, newValue, isLoading, isTemplate) { |
| 2 | + if (isLoading || !newValue || newValue.length < 10) { |
| 3 | + return; |
| 4 | + } |
| 5 | + |
| 6 | + var keywords = [ |
| 7 | + { |
| 8 | + pattern: /password|login|access/i, |
| 9 | + category: 'inquiry | Help ', |
| 10 | + subcategory: 'antivirus', |
| 11 | + priority: '3', |
| 12 | + suggestion: 'This appears to be a Inquiry issue.' |
| 13 | + }, |
| 14 | + { |
| 15 | + pattern: /slow|performance|hanging/i, |
| 16 | + category: 'software', |
| 17 | + subcategory: 'email', |
| 18 | + priority: '2', |
| 19 | + suggestion: 'This appears to be a Software issue.' |
| 20 | + }, |
| 21 | + { |
| 22 | + pattern: /printer|print|printing/i, |
| 23 | + category: 'hardware', |
| 24 | + subcategory: 'monitor', |
| 25 | + priority: '3', |
| 26 | + suggestion: 'This appears to be a Hardware issue.' |
| 27 | + }, |
| 28 | + { |
| 29 | + pattern: /database|data/i, |
| 30 | + category: 'database', |
| 31 | + subcategory: 'db2', |
| 32 | + priority: '3', |
| 33 | + suggestion: 'This appears to be an Database issue.' |
| 34 | + }, |
| 35 | + { |
| 36 | + pattern: /network|internet|wifi|connection/i, |
| 37 | + category: 'network', |
| 38 | + subcategory: 'vpn', |
| 39 | + priority: '2', |
| 40 | + suggestion: 'This appears to be a network issue.' |
| 41 | + } |
| 42 | + |
| 43 | + ]; |
| 44 | + |
| 45 | + var lowerDesc = newValue.toLowerCase(); |
| 46 | + var matched = null; |
| 47 | + |
| 48 | + for (var i = 0; i < keywords.length; i++) { |
| 49 | + if (keywords[i].pattern.test(lowerDesc)) { |
| 50 | + matched = keywords[i]; |
| 51 | + break; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + g_form.hideFieldMsg('short_description', true); |
| 56 | + g_form.clearMessages(); |
| 57 | + |
| 58 | + if (matched) { |
| 59 | + g_form.showFieldMsg('short_description', matched.suggestion, 'info', false); |
| 60 | + |
| 61 | + if (confirm(matched.suggestion + "\n\nApply these suggestions?")) { |
| 62 | + g_form.setValue('category', matched.category); |
| 63 | + g_form.setValue('subcategory', matched.subcategory); // Make sure you use backend value for subcategory! |
| 64 | + g_form.setValue('priority', matched.priority); |
| 65 | + g_form.addInfoMessage('Suggestions applied automatically!'); |
| 66 | + } else { |
| 67 | + g_form.addInfoMessage('Suggestions dismissed.'); |
| 68 | + g_form.hideFieldMsg('short_description', true); |
| 69 | + } |
| 70 | + } else { |
| 71 | + g_form.addInfoMessage('No keywords matched in description.'); |
| 72 | + } |
| 73 | +} |
0 commit comments