- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 01:35 AM
Want to show different Dashbaord as homepage From 9am to 5pm and different from 5pm to 9am how can we achieve that with the help of sys_id.
I have already used fix script to set the value of dashboard homepage in user_preference table but when i am opening a new dashboard it will automatically set as my homepage.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 02:15 AM
may be you can use UI script and check the current time for that logged in user and then set the preference
I haven't tested this though.
1) create UI script and use GlideAjax to set the homepage
2) sample script include
var userId = gs.getUserID();
var now = new GlideDateTime();
var hour = parseInt(now.getDisplayValue().split(' ')[1].split(':')[0], 10);
var ampm = now.getDisplayValue().split(' ')[2];
if (ampm === 'PM' && hour !== 12) hour += 12;
if (ampm === 'AM' && hour === 12) hour = 0;
var dashboardUrl;
// 9am to 5pm
if (hour >= 9 && hour < 17) {
dashboardUrl = '$pa_dashboard.do?embedded=true&sysparm_dashboard=SYS_ID_DAY'; // Replace SYS_ID_DAY
} else {
dashboardUrl = '$pa_dashboard.do?embedded=true&sysparm_dashboard=SYS_ID_NIGHT'; // Replace SYS_ID_NIGHT
}
// Set user preference for homepage
var pref = new GlideRecord('sys_user_preference');
pref.addQuery('user', userId);
pref.addQuery('name', 'my_home_navigation_page');
pref.query();
if (pref.next()) {
pref.value = dashboardUrl;
pref.update();
} else {
pref.initialize();
pref.user = userId;
pref.name = 'my_home_navigation_page';
pref.type = 'string';
pref.value = dashboardUrl;
pref.insert();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 02:15 AM
may be you can use UI script and check the current time for that logged in user and then set the preference
I haven't tested this though.
1) create UI script and use GlideAjax to set the homepage
2) sample script include
var userId = gs.getUserID();
var now = new GlideDateTime();
var hour = parseInt(now.getDisplayValue().split(' ')[1].split(':')[0], 10);
var ampm = now.getDisplayValue().split(' ')[2];
if (ampm === 'PM' && hour !== 12) hour += 12;
if (ampm === 'AM' && hour === 12) hour = 0;
var dashboardUrl;
// 9am to 5pm
if (hour >= 9 && hour < 17) {
dashboardUrl = '$pa_dashboard.do?embedded=true&sysparm_dashboard=SYS_ID_DAY'; // Replace SYS_ID_DAY
} else {
dashboardUrl = '$pa_dashboard.do?embedded=true&sysparm_dashboard=SYS_ID_NIGHT'; // Replace SYS_ID_NIGHT
}
// Set user preference for homepage
var pref = new GlideRecord('sys_user_preference');
pref.addQuery('user', userId);
pref.addQuery('name', 'my_home_navigation_page');
pref.query();
if (pref.next()) {
pref.value = dashboardUrl;
pref.update();
} else {
pref.initialize();
pref.user = userId;
pref.name = 'my_home_navigation_page';
pref.type = 'string';
pref.value = dashboardUrl;
pref.insert();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 05:33 AM
Hello Ankur,
yes it is working fine "Thank You for that" but do we have any method for cache clearing. Because we have to close current session and open new one (after 2-3 min) or need to clear cache. Can we add Something that in active session we can achieve above requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 05:56 AM
Glad to know that it's working.
Please mark my response as correct and close the thread.
The discussion can still continue on answered thread.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 06:14 AM
try this in UI script
// Only run on the homepage/dashboard
if (window.location.pathname.indexOf('pa_dashboard.do') !== -1) {
var now = new Date();
var hour = now.getHours();
var dashboardSysId;
if (hour >= 9 && hour < 17) {
dashboardSysId = 'YOUR_DAY_DASHBOARD_SYS_ID';
} else {
dashboardSysId = 'YOUR_NIGHT_DASHBOARD_SYS_ID';
}
// If not already on the correct dashboard, redirect
if (window.location.search.indexOf(dashboardSysId) === -1) {
window.location.href = '/$pa_dashboard.do?sysparm_dashboard=' + dashboardSysId;
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader