- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2020 05:20 AM
It looks like a recurring question, but none of the advised solutions seem to work. Therefor I'd like to present my case.
Can somebody help to find out what I am missing ?
(1) UI Script
- application: foo
- name: bar
- API name: foo.bar
- ui type: all
- script
var foo = foo || {};
foo.bar = (function() {
"use strict";
return {
helloWorld: function() {
console.warn("It works !");
},
type: "bar"
};
})();
(2) Catalog client script (also application 'foo'):
- g_ui_scripts.getUIScript('foo.bar') => "No script registered with name ..."
- g_ui_scripts.getUIScript('foo') => "No script registered with name ..."
- g_ui_scripts.getUIScript('bar') => "No script registered with name ..."
- g_ui_scripts.getUIScript('foo.bar.helloWorld') => "No script registered with name ..."
- Same with g_ui_scripts[ ... ] => undefined
- ScriptLoader.runScripts( ... ) => ScriptLoader undefined
- ...
Solved! Go to Solution.
- 5,885 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2020 05:07 AM
! SOLVED !
By carefully debugging the JS code in the catalog item page it became apparent why it doesn't work. The code of the UI script is expected to be executable. The ui script is the result of this invocation. The bottom line is that the proposed default ui script template is invalid for a scope ui script.
My example should therefore be rewritten as:
(function() {
"use strict";
return {
helloWorld: function() {
console.warn("It works !");
},
type: "bar"
};
})();
And the invocation:
g_ui_scripts.getUIScript('foo.bar').then(function(script) {
script.helloWorld();
});
When saving the ui script for the first time there will be a warning about invalid implementation of the ui script. I ignored the error because there is no other way to implement the script for it to be accepted.
Hope this helps other people too.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2020 06:51 AM
Hi
tried using GlideUIScripts or ScriptLoader? I can't remember whether either of those is available in a scoped application.
Access UI scripts from within client-side code.
There is no constructor for this class. Access methods using the g_ui_scripts global object in any client-side code, such as client or validation scripts.
If calling a UI script with UI Type set to Mobile / Service Portal, use the g_ui_scripts['nameOfScript'];
syntax. If calling a UI script with the UI Type set to All or Desktop, use the getUIScript() method to load the script. However, this method is not supported in Internet Explorer 11 when called outside of the Angular application environment. If calling a UI script outside of an Angular context using IE11, you must call the script directly.
If it help mark helpful or correct
Thanks and regards
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2020 07:29 AM
Yep. As indicated, been there done that. Hence my question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2020 07:45 AM
Hi,
As per below question it seems they were able to achieve this as this question is answered
if that doesn't help then
Looks like creating reusable UI Scripts in a scope will not work. I created a global UI script in the Global scope so that it can be used in a client script of custom scoped application.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2020 06:15 AM
Is the consensus that it actually isn't possible ? Without adding it to the theme that is.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2020 06:36 PM
I believe so
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022