forked from ServiceNowDevProgram/code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetUsersFavoriteHierarchy.js
More file actions
53 lines (50 loc) · 1.93 KB
/
GetUsersFavoriteHierarchy.js
File metadata and controls
53 lines (50 loc) · 1.93 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Example call with print out. You can replace gs.getUserID() with a User Name instead
var favorites = getFavoritesHierarchyArray(gs.getUserID());
gs.info(JSON.stringify(favorites));
function getFavoritesHierarchyArray(userId) {
var hierarchy = [];
addGroups("NULL", hierarchy, userId);
addItems("NULL", hierarchy, userId);
return hierarchy;
}
function addGroups(parentId, array, name) {
var grBookmarkGroup = new GlideRecord("sys_ui_bookmark_group");
grBookmarkGroup.addEncodedQuery("user=" + name + "^parent_group=" + parentId);
grBookmarkGroup.query();
while (grBookmarkGroup.next()) {
var groupObj = {
"type": "group",
"color": grBookmarkGroup.getValue("color"),
"order": grBookmarkGroup.getValue("order"),
"title": grBookmarkGroup.getValue("title"),
"items": [],
};
array.push(groupObj);
addGroups(grBookmarkGroup.getUniqueValue(), groupObj.items, name);
addItems(grBookmarkGroup.getUniqueValue(), groupObj.items, name);
}
}
function addItems(parentGroup, array, name) {
var grBookmark = new GlideRecord("sys_ui_bookmark");
grBookmark.addEncodedQuery("user=" + name + "^group=" + parentGroup);
grBookmark.query();
while (grBookmark.next()) {
var grBookmarkObj = {
"type": "bookmark",
"color": grBookmark.getValue("color"),
"order": grBookmark.getValue("order"),
"icon": grBookmark.getValue("icon"),
"open_in_form": grBookmark.getValue("open_in_form"),
"pinned": grBookmark.getValue("pinned"),
"separator": grBookmark.getValue("separator"),
"title": grBookmark.getValue("title"),
"ui_type": grBookmark.getValue("ui_type"),
"uncancelable": grBookmark.getValue("uncancelable"),
"url": grBookmark.getValue("url"),
"flyout": grBookmark.getValue("flyout"),
"flyout_sizing": grBookmark.getValue("flyout_sizing"),
"flyout_width": grBookmark.getValue("flyout_width"),
};
array.push(grBookmarkObj);
}
}