|
22 | 22 | /* Get Catalog ID */ |
23 | 23 | var catalogsId = $sp.getParameter("used_catalog") || options.used_catalog; |
24 | 24 |
|
25 | | - /* Get all catalog items */ |
| 25 | + /* Get all catalog items which are active and not marked hidden on service portal */ |
26 | 26 | var catalogItems = new GlideRecordSecure('sc_cat_item'); |
27 | 27 | catalogItems.addQuery('sc_catalogs', 'IN', catalogsId); |
28 | 28 | catalogItems.addQuery('active', true); |
| 29 | + catalogItems.addQuery('hide_sp', false); |
29 | 30 | catalogItems.orderBy('name'); |
30 | 31 | catalogItems.query(); |
31 | 32 |
|
|
51 | 52 | itemId: catalogItems.getUniqueValue(), |
52 | 53 | name: catalogItems.getValue('name'), |
53 | 54 | description: catalogItems.getValue('short_description'), |
| 55 | + type: catalogItems.getDisplayValue('sys_class_name'), |
54 | 56 | externalUrl: extUrl |
55 | 57 | }); |
56 | 58 | } |
|
59 | 61 | data.catalogCategories = getUniqueFirstLetters(data.catalogItems); |
60 | 62 |
|
61 | 63 | function getUniqueFirstLetters(strings) { |
62 | | - /* Create an empty array to store the first letters */ |
63 | | - var firstLetters = []; |
| 64 | + /* Create an object to store unique first letters */ |
| 65 | + var firstLettersMap = {}; |
64 | 66 |
|
65 | | - /* Iterate over the input array of strings */ |
66 | | - for (var i = 0; i < strings.length; i++) { |
67 | | - /* Get the first letter of the current string */ |
68 | | - var firstLetter = strings[i].name.charAt(0); |
69 | | - var exists = false; |
| 67 | + /* Iterate over the input array of strings */ |
| 68 | + for (var i = 0; i < strings.length; i++) { |
| 69 | + /* Get the first letter of the current string and convert it to uppercase */ |
| 70 | + var firstLetter = strings[i].name.charAt(0).toUpperCase(); |
70 | 71 |
|
71 | | - /* Check if the letter already exists in the array */ |
72 | | - for (var j = 0; j < firstLetters.length; j++) { |
73 | | - if (firstLetters[j].letter === firstLetter.toUpperCase()) { |
74 | | - exists = true; |
75 | | - break; |
76 | | - } |
77 | | - } |
| 72 | + /* Use the letter as a key in the object to ensure uniqueness */ |
| 73 | + if (!firstLettersMap[firstLetter]) { |
| 74 | + firstLettersMap[firstLetter] = true; |
| 75 | + } |
| 76 | + } |
78 | 77 |
|
79 | | - /* Check if the first letter already exist in the array */ |
80 | | - if (!exists) { |
81 | | - /* If not add it */ |
82 | | - firstLetters.push({ |
83 | | - letter: firstLetter, |
84 | | - selected: false |
85 | | - }); |
86 | | - } |
87 | | - } |
| 78 | + /* Convert the object keys to an array of objects */ |
| 79 | + var firstLetters = []; |
| 80 | + for (var letter in firstLettersMap) { |
| 81 | + if (firstLettersMap.hasOwnProperty(letter)) { |
| 82 | + firstLetters.push({ |
| 83 | + letter: letter, |
| 84 | + selected: false |
| 85 | + }); |
| 86 | + } |
| 87 | + } |
88 | 88 |
|
89 | | - /* Sort the array of objects, otherwise the simplier version of sort might be used */ |
90 | | - firstLetters.sort(function (a, b) { |
91 | | - return a.letter.localeCompare(b.letter); |
92 | | - }); |
| 89 | + /* Sort the array of objects */ |
| 90 | + firstLetters.sort(function (a, b) { |
| 91 | + return a.letter.localeCompare(b.letter); |
| 92 | + }); |
93 | 93 |
|
94 | | - /* Return the sorted array of unique first letters */ |
95 | | - return firstLetters; |
| 94 | + /* Return the sorted array of unique first letters */ |
| 95 | + return firstLetters; |
96 | 96 | } |
97 | 97 | })(); |
0 commit comments