logo

NJP

Provision your PDI or company/customer instances quicker, smarter (03): Favorite Favorites

Import · May 26, 2020 · article

Favorites

Make a list of your personal favorites. Some of mine for example:

- Customer Updates

Updated by me AND Updated on Last 7 days- System Log

Created on Today

- Background Script- Fix ScriptActually, I would like to group these. So it does not only concern the Bookmark records [sys_ui_bookmark], though also a Bookmark Group record [sys_ui_bookmark_group]. This is also a piece often missing on ServiceNow Community answers. Loads of answers that Favorites consist of sys_ui_bookmark records, though almost never, the sys_ui_bookmark_group records are mentioned!

Fix Script

Knowing the above, how can we turn this into an Update Set or XML? Actually in this case I would choose a Fix Script. Because you could run this also on a company/customer instance, where you have been given a personal user account. A personal user account, where the user record will have a different sys_id as the template you've set up for your PDI.

We could add the below script to the Fix Script of the previous blog.

var grBookmark = new GlideRecord('sys_ui_bookmark');
grBookmark.addQuery('user', userSysId);
grBookmark.deleteMultiple();

var grBookmarkGroup = new GlideRecord('sys_ui_bookmark_group');
grBookmarkGroup.addQuery('user', userSysId);
grBookmarkGroup.deleteMultiple();

var grBookmarkGroup = new GlideRecord('sys_ui_bookmark_group');
grBookmarkGroup.initialize();
grBookmarkGroup.setValue('title', 'Development');
grBookmarkGroup.setValue('user', userSysId);
grBookmarkGroup.setValue('color', 'normal');
grBookmarkGroup.insert();

var bookmarkObj = [
    {
        'icon' : 'list',
        'color' : 'green',
        'title' : 'Customer Updates > Me, Last 7 days',
        'url' : 'sys_update_xml_list.do?sysparm_query=sys_updated_by%3Djavascript:gs.getUserName()%5Esys_updated_onONLast%207%20days%40javascript:gs.beginningOfLast7Days()%40javascript:gs.endOfLast7Days()'
    },
    {
        'icon' : 'list',
        'color' : 'green',
        'title' : 'System Log > Today',
        'url' : 'syslog_list.do?sysparm_query=sys_created_onONToday%40javascript:gs.daysAgoStart(0)%40javascript:gs.daysAgoEnd(0)'
    },
    {
        'icon' : 'console',
        'color' : 'red',
        'title' : 'Background Script',
        'url' : '/sys.scripts.do'
    },
    {
        'icon' : 'console',
        'color' : 'red',
        'title' : 'Fix Script',
        'url' : '/sys_script_fix.do?sys_id=-1'
    }
];

for(var i = 0; i < bookmarkObj.length; i++) {
    var grBookmark = new GlideRecord('sys_ui_bookmark');
    grBookmark.initialize();
    grBookmark.setValue('group', grBookmarkGroup.getUniqueValue());
    grBookmark.setValue('user', userSysId);
    grBookmark.setValue('icon', bookmarkObj[i].icon);
    grBookmark.setValue('color', bookmarkObj[i].color);
    grBookmark.setValue('order', i + 1);
    grBookmark.setValue('title', bookmarkObj[i].title);
    grBookmark.setValue('url', bookmarkObj[i].url);
    grBookmark.insert();
}

This would already create your Favorites within a Group. By default, the group would be collapsed. So let's add below code to the User Preferences of the previous blog:

{
    'name' : 'favorite.' + grBookmarkGroup.getUniqueValue() + '.expanded',
    'value' : 'true'
},

After running the Fix Script and refreshing your browser, your Favorites would look like:

image

Applying Plugins

We made another nice step in provisioning your PDI or company/customer non-production instance with applying your favorite Favorites. Next-up: Applying Plugins.

Keep an eye out for the next blog where I'll write about applying your favorite plugins rapidly!

---

If any questions or remarks, let me know!

Kind regards,

Mar k Roethof

ServiceNow Technical Consultant @ Quint Technology

1x ServiceNow Developer MVP

1x ServiceNow Community MVP

---

LinkedIn

View original source

https://www.servicenow.com/community/developer-blog/provision-your-pdi-or-company-customer-instances-quicker-smarter/ba-p/2287999