Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Default Dashboard in Service Operations Workspace

Nicolas17
Tera Expert

Hello community!

Our Service Desk Manager built himself a custom dashboard in Service Operations Workspace (SOW) and would love to land on it by default when clicking the "Dashboard" button in the left ribbon.

 

Right now, every time he logs back in and goes to that section, it opens the default IT Agent Dashboard instead.

I tried setting the Default Dashboard value in the Service Operations Workspace Experience in UI Builder (see screenshot), but it doesn't seem to have any effect.

 

So my questions are:

  • Is there a way to change the default dashboard for all users (or ideally per user)?

  • Or even better: is there a way to load the last opened dashboard, like what we see in Next Experience UI?

 

Any tips would be really appreciated!

Thanks in advance!

6 REPLIES 6

koenjochems
Tera Contributor

You can change the default dashboard via the UI Builder. In the SOW experience go to the IT Agent Dashboard page. The default dashboard is hard code in the Data resources -> Dashboard controller. Just change the dashboardSysId to your preference.

Cheri M
Kilo Sage

After asking if you’d found a solution, I finally got something to work.
*Edited* – I originally thought it was working, but later found that user preferences weren’t saving (which is probably why this doesn’t work out of the box). I’ve updated the instructions and scripts below to what’s currently working.

Steps:

  1. In UI Builder, open the Service Operations Workspace experience.
    Find and duplicate the page IT Agent Dashboard Default so you can customize it.

    This keeps the original page untouched and gives you a safe copy to modify.

  2. On your new page, select the Dashboard in the left column, then remove the preset from the Dashboard component in the right column.

    Removing the preset unlocks the fields so you can control which dashboard loads.

  3. Create a Scriptlet data resource (I named mine lastDashboardPref) and use the script below:

    This reads the user’s last-used dashboard (or falls back) so SOW can open to it.

function transform(input) {
var my = gs.getUser().getPreference('sow.dashboard.sys_id') || '';
var paId = '';
var gr = new GlideRecord('sys_user_preference');
gr.addQuery('user', gs.getUserID());
gr.addQuery('name', 'com.snc.pa.ui.preferences_dashboards');
gr.orderByDesc('sys_updated_on');
gr.setLimit(1);
gr.query();
if (gr.next()) {
try {
var obj = JSON.parse(gr.getValue('value') || '{}');
// Prefer durable keys first
paId =
obj.last ||
(obj.state && obj.state.activeDashboard) ||
(obj.recent && Array.isArray(obj.recent) && obj.recent[0] && obj.recent[0].sys_id) ||
'';
} catch (e) {}
}
return { value: my || paId || '' };
}

4. Create another Scriptlet data resource (I named mine setDashboardPref) and use the script below:

This saves the user’s current dashboard choice to their preferences.

(function(input){
if (!input || !input.sysId) return { ok:false };
gs.getUser().savePreference('sow.dashboard.sys_id', String(input.sysId));
return { ok:true };
})(input);

5. Create a Client Script in UI Builder and use the following:

This quietly watches for dashboard changes and calls the “save” scriptlet.

function handler({ api }) {
var last = '';
function tick() {
var ctrl = api.data.get('dashboard_controller') || {};
var data = ctrl.data || {};
var active = data.activeTab || {};
var current = active.sys_id ? String(active.sys_id) : '';
if (current && current !== last) {
last = current;
api.serverRequest('setDashboardPref', { sysId: current });
}
setTimeout(tick, 1500);
}
tick();
}

After saving, select this script from the “Select a data resource” screen when prompted.

6. Go back to your Dashboard component and in the right column, bind the “Default Dashboard” field to your new data resource: @Data.lastDashboardPref_1.value

This tells the component to open whatever sys_id your reader returns.

7.  In the left column, open Dashboard controller. Set the dashboardSysId to the dashboard you want as your default. Under filterId, update the value to @Data.lastDashboardPref_1.

The controller uses your default first, then your reader to override it per user.

CheriM_0-1760741614305.png

This might be a little hacky, but it works. Now Service Operations Workspace opens to the last dashboard you viewed instead of always showing the default. Attaching a wild screenshot to help locate things if you’re not familiar with UI Builder.

I hope this works for you too!