The CreatorCon Call for Content is officially open! Get started here.

Service Portal VS Platform UI - window === null NOT WORKING

G24
Kilo Sage

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:

001.png

 

Portal Behavior (as expected):

0002.png

 

Requested Item Behavior (NOT what I was expecting):

0004.png

 

Catalog Task Behavior (also NOT what I was expecting):

0004.png

 

Sources:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0744257 

https://www.servicenow.com/community/now-platform-forum/in-client-scripts-how-to-check-where-the-for... 

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/build/service-portal/concept/unsupp... 

https://www.servicenow.com/community/developer-forum/how-to-script-if-serviceportal-client-script/m-... 

 

1 ACCEPTED SOLUTION

Alex Tod1
Kilo Sage

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.

View solution in original post

9 REPLIES 9

-O-
Kilo Patron

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.

Alex Tod1
Kilo Sage

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.

G24
Kilo Sage

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

-O-
Kilo Patron

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.