Provision your PDI or company/customer instances quicker, smarter (02): Recommended System Properties and User Preferences
Obviously, you could extend this list enormously. For example looking at the ServiceNow instance hardening guide, tens of System Properties are listed! The above ones though would benefit you greatly on a PDI and on company/customer non-production instances.
Note: Read about logpoints in one of my ServiceNow Community articles: Forget about adding log statements to Server Side script, use logpoints! [Orlando]
You could add these System Properties to an Update Set. Obviously you could also use an XML for this, or a Fix Script. That's up to you. I would keep these separated from the template user record from the previous blog, as the template user record would only fit your PDI while these System Properties could be used on company/customer non-production instances.
User Preferences
A real time saver and an annoying one: Having to set up your user preferences all over! Make a list of your common valuable user preferences. For example:
- glide.ui.application_picker.in_header- glide.ui.update_set_picker.in_header- glide.ui.related_list_timing- rowcount- com.glideapp.dashboards.homepage_notification.dont_ask_me_again- home_refresh
- table.highlighting
You could also add user preferences for the ordering on lists. For example:
- syslog.db.order.direction- syslog.db.order- sys_update_xml.db.order.direction
- sys_update_xml.db.order
User record
On company/customer instances you probably would be given a personal user account. A user record created by an administrator, and therefore different than the template you've setup. How annoying is it, that the preferred language, time zone, date format are off!
UI Lists
A common action would be to personalize certain lists, maybe even view specific. For example:
- sys_update_xml
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.
The start of the Fix Script would contain defining which user it concerns. The logged-in user, so your user record.
(function() {
var userSysId = gs.getUserID();
})();
Updating the user record settings like preferred language, timezone, date format.
var grUser = new GlideRecord('sys_user');
grUser.get(userSysId);
grUser.setValue('preferred_language', 'en');
grUser.setValue('time_zone', 'Europe/Amsterdam');
grUser.setValue('date_format', 'dd-MM-yyyy');
grUser.update();
Adding personalized lists.
var grPersonalizeList = new GlideRecord('sys_ui_list');
grPersonalizeList.addQuery('sys_user', userSysId);
grPersonalizeList.deleteMultiple();
var personalizelistObj = [
{
'name' : 'sys_update_xml',
'parent' : '',
'view' : 'Default view',
'element' : 'type, target_name, name, action, update_set, sys_updated_by, sys_updated_on'
},
{
'name' : 'sys_update_xml',
'parent' : 'sys_update_set',
'view' : 'Default view',
'element' : 'type, target_name, action, sys_updated_by, sys_updated_on'
}
];
for(var i = 0; i < personalizelistObj.length; i++) {
var grPersonalizeList = new GlideRecord('sys_ui_list');
grPersonalizeList.initialize();
grPersonalizeList.setValue('name', personalizelistObj[i].name);
grPersonalizeList.setValue('parent', personalizelistObj[i].parent);
grPersonalizeList.setValue('sys_user', userSysId);
grPersonalizeList.setValue('view', personalizelistObj[i].view);
grPersonalizeList.insert();
var elementArr = personalizelistObj[i].element.split(',');
for(var j = 0; j < elementArr.length; j++) {
var grPersonalizeListColumn = new GlideRecord('sys_ui_list_element');
grPersonalizeListColumn.initialize();
grPersonalizeListColumn.setValue('element', elementArr[j].trim());
grPersonalizeListColumn.setValue('position', j);
grPersonalizeListColumn.setValue('list_id', grPersonalizeList.getUniqueValue());
grPersonalizeListColumn.insert();
}
}
Inserting user preferences.
var grUserPreference = new GlideRecord('sys_user_preference');
grUserPreference.addQuery('user', userSysId);
grUserPreference.deleteMultiple();
var userpreferenceObj = [
{
'name' : 'glide.ui.application_picker.in_header',
'value' : 'true'
},
{
'name' : 'glide.ui.update_set_picker.in_header',
'value' : 'true'
},
{
'name' : 'glide.ui.related_list_timing',
'value' : 'deferred'
},
{
'name' : 'rowcount',
'value' : '100'
},
{
'name' : 'syslog.db.order.direction',
'value' : 'DESC'
},
{
'name' : 'syslog.db.order',
'value' : 'sys_created_on'
},
{
'name' : 'sys_update_xml.db.order.direction',
'value' : 'DESC'
},
{
'name' : 'sys_update_xml.db.order',
'value' : 'sys_updated_on'
},
{
'name' : 'com.glideapp.dashboards.homepage_notification.dont_ask_me_again',
'value' : 'true'
},
{
'name' : 'home_refresh',
'value' : 'off'
},
{
'name' : 'table.highlighting',
'value' : 'false'
}
];
for(var i = 0; i < userpreferenceObj.length; i++) {
var grUserPreference = new GlideRecord('sys_user_preference');
grUserPreference.initialize();
grUserPreference.setValue('user', userSysId);
grUserPreference.setValue('name', userpreferenceObj[i].name);
grUserPreference.setValue('value', userpreferenceObj[i].value);
grUserPreference.insert();
}
After running the above script, al of the mentioned user settings, personalized lists and user preferences would be updated/generated for the account on which you are logged in.
Favorite Favorites
With the System Properties and User Preferences (and some user record settings and personalized lists) we've made a really nice step in provisioning your PDI or company/customer non-production instance and your personal user account. Next up would be another really annoying one... Favorites!
Keep an eye out for the next blog where I'll write about setting up your favorite Favorites 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
---
https://www.servicenow.com/community/developer-blog/provision-your-pdi-or-company-customer-instances-quicker-smarter/ba-p/2288015