Two items I have to call out. First, this was inspired by Ratesh Shah's post. Second, you can read "Official" client script restrictions here on the docs.
Client Scripting issues
The Service Portal has more restrictions on it then the classic UI. In the past, any DOM manipulation or access and use of window across scripts was frowned on. With the Service Portal ServiceNow has removed the ability to mess with the Document Object Model (DOM). If you want to use those you'll have to change your scripts below.
Unsupported client scripting globals
The following globals and APIs are unavailable in client scripts in the Service Portal.
Thing | Description of the thing |
---|---|
window | This is a object used by all browsers |
document | This is a object used by all browsers |
$ | Prototypejs selector |
$$ | Prototypejs css selector |
jQuery | jQuery |
$j | Alias for jQuery |
angular | Angular |
jslog | Docs |
gel | Shortcut for window.getElementByID() |
Re-usable utility functions
Macros and any Jelly are not supported on Service Portal. Two ways around this is Widget dependencies or the ScriptLoader utility.
Widget Dependencies
In Service Portal, you can add widget dependencies for re-usable utility functions.
ScriptLoader
Another way would be to add a ScriptLoader to the client script.
UI Type for Catalog Client Scripts and Catalog UI Policies
If you want a catalog client script to work on both service portal / mobile and regular platform, you must select UI Type = ALL or service portal / mobile. It may be tempting to update every client script's UI Type to All. for all catalog client scripts, but it may not be a good idea for performance reasons. Sometimes, there is a valid reason not to make the catalog client script available on portal due to functional reasons.
If you want a catalog UI policy to work on both service portal / mobile and regular platform, you must select Run scripts in UI Type = All. Use All, Desktop or Service Portal / Mobile based on your ask as explained above. This field is not available on the form, you can change it from list view.
You can use window object to detect if your catalog item is being used in Service Portal or CMS (Rest of platform).
if (window) {
// you are in CMS
} else {
// you are in Service Portal</em>
}