- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2022 02:34 PM
I have a client script that updates a RITM when an Interaction type is 'Request'. It copies a 'Yes' or 'No' value from the Interaction over to the RITM
However it seems like it's throwing an error on the Portal view "there is a Javascript error in your browser console" the error is 'typeerror: window is null'
How can i set this script to not load on the Portal view? We don't create Interactions from there.
Or, is there another way to get this to work?
Thanks!
function onLoad() {
//Type appropriate comment here, and begin script below
var urlParams = new URLSearchParams(window.location.href);
var data=urlParams.get("u_is_this_being_submitted_for_a_provider_physician_or_app");
g_form.setValue("is_this_being_submitted_for_a_provider_physician_or_app",data);
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2022 03:28 AM
I have just tested this in PDI and I observed the following behavior.
function onLoad() {
if (window === null) { // For portal
//top.location.href; will work in portal
//top.window.location.href; will work in portal
//top.document.location.href; will work in portal
//window.location.href; will not work in portal because window is null in portal
//document.location.href; will not work in portal because document is null in portal
alert('Portal Top: ' + top.location.href);
alert('Portal Top.Window: ' + top.window.location.href);
alert('Portal Top.Document: ' + top.document.location.href);
alert('Document Object: ' + document);
alert('Window Object: ' + window);
alert('Top Object: ' + top);
} else { // For Native UI
//top.location.href; will work in Native UI
//top.window.location.href; will work in Native UI
//top.document.location.href; will work in Native UI
//window.location.href; will work in Native UI
//document.location.href; will work in Native UI
alert('Native UI Top: ' + top.location.href);
alert('Native UI Top.Window: ' + top.window.location.href);
alert('Native UI Window: ' + window.location.href);
alert('Native UI Top.Document: ' + top.document.location.href);
alert('Native UI Document: ' + document.location.href);
alert('Document Object: ' + document);
alert('Window Object: ' + window);
alert('Top Object: ' + top);
}
}
- Scenario 1:
- Catalog Client Script UI Type = All
- Isolate = False
- If block will be executed in portal, else block will be executed in Native UI.
- Scenario 2:
- Catalog Client Script UI Type = All
- Isolate = True
- If block will be executed in portal and Native UI both, else block will not be executed in portal and Native UI.
- window and document will be null, to access them top will be used.
- Scenario 3:
- Catalog Client Script UI Type = Desktop
- Isolate = False
- No block will be executed in Portal, else block will be executed in Native UI.
- Scenario 4:
- Catalog Client Script UI Type = Desktop
- Isolate = True
- No block will be executed in Portal, if block will be executed in Native UI.
- window and document will be null, to access them top will be used.
- Scenario 5:
- Catalog Client Script UI Type = Mobile / Service Portal
- Isolate = False
- No block will be executed in Native UI, if block will be executed in Portal.
- window and document will be null, to access them top will be used.
- Scenario 6:
- Catalog Client Script UI Type = Mobile / Service Portal
- Isolate = True
- No block will be executed in Native UI, if block will be executed in Portal.
- window and document will be null, to access them top will be used.
Now coming to your question,
Was it working fine in Native UI before?
If it was working fine in Native UI, then try the below script. Make sure to uncheck Isolate checkbox and UI type should be All.
function onLoad() {
var params;
var data;
if (window === null) { // For portal
urlParams = new URLSearchParams(top.window.location.href);
data = urlParams.get("u_is_this_being_submitted_for_a_provider_physician_or_app");
g_form.setValue("is_this_being_submitted_for_a_provider_physician_or_app", data);
} else { // For Native UI
urlParams = new URLSearchParams(window.location.href);
data = urlParams.get("u_is_this_being_submitted_for_a_provider_physician_or_app");
g_form.setValue("is_this_being_submitted_for_a_provider_physician_or_app", data);
}
}
If you want this to be executed in Native UI then change UI type to Desktop and remove the if block along with the script inside and remove the else without removing the script inside.
By the way when I used urlParams.get(), I was only able to get those parameters which start with sysparm_ e.g., urlParams.get('sysparm_view') was working fine but urlParams.get('sys_id') was returning null.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2022 04:02 PM
Hi,
client scripts are set to be isolated by default and access to the window object is not available. To change this behaviour, add the "isolate script" checkbox to the form and deselect it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2022 10:34 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2022 12:21 AM
Looking at previous client script of mine, I use the following to avoid errors between UI16 and portal
var hrefPath = (typeof gel == 'undefined') ? this.location.href : top.location.href;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2022 11:07 AM
Where might i put that in my above script?