
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 01:47 PM
Smart folks,
It's embarrassing that I have to ask this, because I thought I knew the answer, and I though the answer worked, but...
I have multiple sources telling me the same thing, that I can use the following code to determine, in script, at runtime, if the user is in the Service Portal or in the Platform UI:
if (window === null)
But that is NOT working for me. What am I doing wrong???
Catalog Client Script:
Portal Behavior (as expected):
Requested Item Behavior (NOT what I was expecting):
Catalog Task Behavior (also NOT what I was expecting):
Sources:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0744257
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 03:20 PM
Hello @G24,
I leave you here an interesting article that have to clarifies the global variable thing: https://www.servicenow.com/community/developer-articles/top-window-document-objects-in-native-ui-and...
You forgot to check that the isolate script flag is set to false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 02:29 PM - edited 09-20-2023 02:30 PM
You also need to set the "Isolate script" flag to false.
But a way simpler and more robust solution would be to create two Client Scripts: one for each environment flagged as such through UI Type field.
Then the determination of the current environment would be automatically handled by the system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 03:20 PM
Hello @G24,
I leave you here an interesting article that have to clarifies the global variable thing: https://www.servicenow.com/community/developer-articles/top-window-document-objects-in-native-ui-and...
You forgot to check that the isolate script flag is set to false.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 03:42 PM
@-O- and @Alex Tod1
That did in fact allow me to differentiate between Portal and Platform by testing the "window" variable. Thank you. However, I DO NOT WANT to change my script to isolate == false. I like being isolated. I like being in default world.
So how can I test for Platform VS Portal *** IN ALL CASES ***. I don't want to even THINK about whether or not my script is isolated or not. Would love to see what you might come up with. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 04:09 PM
You can go in two directions from there:
- even further away from normal, e.g. testing URL, or DOM - clearly not the direction you want
- as mentioned before: two Client Scripts one where UI Type == Desktop - this will only run in Core UI and another where UI Type is Mobile / Service Portal - this will only run in Portal.