Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This script will allow you to get Favorites Hierarchy of a specific user.
This means all nested groups and links.

Here is an 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));


This will return an array of objects.
Each item in the array will have a "type" property which will be "group" for nested groups and "bookmark" for bookmarks/links

Other properties are named the same as the standard fields on the "sys_ui_bookmark_group" and "sys_ui_bookmark" tables for Groups and Bookmark types respectively
Loading