How to determine if you are in Workspace in a Client Script

Community Alums
Not applicable

I'm currently in the process of setting up Agent Workspace to allow users to work on Incidents. We have a number of custom client scripts that run on Incident that i need to configure to work correctly in workspace. Is there a way to determine which UI you are in? I know there is the GlideURI server-side api which i could use to pull apart the uri to determine i'm in workspace but was wondering if there is anything on the client-side i could use? window.location.href doesn't work in workspace either...

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use the view name i.e. workspace to make client scripts run on workspace

OR

you can check URL

if it contains 'now/agent/workspace' then it's workspace and not native UI

var url = top.location.href;

if(url.indexOf('now/agent/workspace')){

// workspace

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use the view name i.e. workspace to make client scripts run on workspace

OR

you can check URL

if it contains 'now/agent/workspace' then it's workspace and not native UI

var url = top.location.href;

if(url.indexOf('now/agent/workspace')){

// workspace

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Community Alums
Not applicable

Thanks. top.location.href works in workspace which is useful so i may use that and pull it apart to determine the view. With regards to your first point when you say I can use the view name, what do you mean? How would I determine the view I am in?

Hi,

we usually create view with name as "workspace" on the table.

then create workspace view rules to show that view in workspace

But you need not worry on all these;

you can use the top.location.href for your solution

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Community Alums
Not applicable

Right ok using a view rule... So there's no ServiceNow provided API to determine which view or UI you are in on the client-side then? Thanks.