- 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-08-2025 10:54 PM
Hope you are doing good.
Did my reply answer your question?
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 03:56 AM
Hello,
Use a Scripted Redirect to send users to different dashboards based on time (9am–5pm vs 5pm–9am) using their sys_id. This avoids modifying user_preference and prevents homepage override. Example:
(function redirectUser(request, response) {
var hour = new GlideDateTime().getHourLocalTime();
var targetSysId = (hour >= 9 && hour < 17) ? 'day_dashboard_sysid' : 'night_dashboard_sysid';
response.sendRedirect('/$pa_dashboard.do?sys_id=' + targetSysId);
})(request, response);
Best Regard,
Sally