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!

10 REPLIES 10

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!

Hi @Cheri M I'm trying to follow your steps but running into issues.  Ultimately, I can't get the sow.dashboard.sys_id user preference to actually create/update. Is that working in your instance?

 

It does seem to load the user's last dashboard, but I think only because of the com.snc.pa.ui.preferences_dashboards OOB user preference.

 

  1. Do the scriplet data resources require Properties/Output schema? 
  2. I had no Dashboard controller, so I manually created it. Then I applied the pre-set that was available, which populated the Data broker response with @data.dashboard_controller_1.data.
  3. Using console.log in the setDashboardPref 1 script, I found that this was always null:
var ctrl = api.data.get('dashboard_controller_1') || {};

But then I found that I can get the dashboard sys ID from event.payload.params.dashboardSysId

  • Now, I'm finding that this line isn't working:

api.serverRequest('setDashboardPref', { sysId: current });

I read online & found similar examples that appear it should look more like this:

api.data.setdashboardpref_1.execute({"sysId": current });

But still, setDashboardPref never seems to run and I cannot figure out why. 

 

Any help you may be able to give is greatly appreciated, and please let me know if I can clarify anything.

I finally got something working that was somewhat based off of what you had. Here was my solution in case it helps anyone else. 

 

The OOB user preference "com.snc.par.dashboards.ui.preferences" is already saving the most recent dashboard, so what I did was use a script to return the most recent or a default if no user preference existed. This removed the need to try saving the most recent dashboard to a custom user preference. 😊

 

 

  • 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.

  • 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.

  • Create a Transform 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. Be sure to edit the default_dashboard_sys_id in the script. 

function transform(input) {
	var dashboardId = '';

	// Get user's last dashboard preference
	var gr = new GlideRecord('sys_user_preference');
	gr.addQuery('user', gs.getUserID());
	gr.addQuery('name', 'com.snc.par.dashboards.ui.preferences');
	gr.orderByDesc('sys_updated_on');
	gr.setLimit(1);
	gr.query();

	if (gr.next()) {
		try {
			var raw = gr.getValue('value') || '{}';
			var parsed = JSON.parse(raw);

			if (parsed.recent) {
				var recentArr = JSON.parse(parsed.recent);
				if (recentArr[0] && recentArr[0].sys_id) {
					dashboardId = recentArr[0].sys_id;
				}
			}
		} catch (e) {
			gs.warn('lastDashboardPref parse error: ' + e);
		}
	}

	// Fallback to default if none
	if (!dashboardId) {
		dashboardId = 'default_dashboard_sys_id'; // The sys_id for the dashboard that you would like to be default
	}

	// Object with a "value" field for UIB
	return {"value": dashboardId.toString()};
}
  • Add the following Output schema to the Transform data resource
[{
  "name": "value",
  "label": "Value",
  "description": "value",
  "readOnly": false,
  "fieldType": "json"
}]​
  • Create a new ACL with the following configuration:
    1. Type = ux_data_broker
    2. Operation = Execute
    3. Decision type = Allow if
    4. Name = the sys_id of the sys_ux_data_broker_transform record you created.
      1. I have no idea how ServiceNow wants you to create these. I used sn utils to make the name field un-mandatory, so I could create the record, then I used a background script to set the name field to the value of the sys_id. ¯\_(ツ)_/¯
    5. Roles = Whomever this should apply to. I just used snc_internal & figure that SOW's configuration will be what is ultimately controlling access. 
  • Return to UI Builder and add the new transform data resource as a data resource on your page variant. 
  • Select the Dashboard in the left column, then click Bind data or use scripts for the default dashboard in the right column. 
  • Bind the following to the default dashboard: @Data.lastdashboardpref.value.value
    Be aware that lastdashboardpref will be the name of the data resource you added to the page variant. You may need to modify this value to match your own configuration. 
    Patrick85_0-1765328619958.png

     

I'm sure someone will point out a better or easier solution eventually, but finally after several hours of trying, something works!

VanceM
Tera Contributor

Good afternoon!

I believe if you clear the attribute 'Default Dashboard' under 'Dashboard 1' within the 'IT Agent Dashboard' variant on the Service Operations Workspace experience, it will display the user's last visited dashboard.

VanceM_0-1765573169407.png