How to use UI script in service portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 05:16 AM
UI script is not working getting error "Uncaught ReferenceError: Class is not defined" on service Portal, and this error is caused by using the class.create in UI script.
We have include the UI script in Theme.
Any help is much appreciated.
Thanks,
Aishwarya
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 05:19 AM
You have to add the UI Script as a dependancy on your widget i believe.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2019 05:23 AM
Hi Aishwarya,
1. Create UI script.
2. goto -> Service Portal -> Dependency-> New
1. check "include page on load"
2. select the page to load
3. add the JS Includes -> new and your UI script here.
4. Go to the widget which is included in your page.
1. go to the related list " Dependencies"
2. click "Edit"
3. Add the JS includes added in step 3.
Mark If Correct/Helpful
Regards,
Ajay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2019 02:52 PM
I guess your UI Script looks like this:
var myClass = Class.create();
myClass.prototype = {
myMethod: function() {
// do something
}
myOtherMethod: function() {
// do something else
}
};
You can avoid Class.create() by using a different object design pattern:
var myClass = function() {
this.myMethod = function() {
// do something
};
};
myClass.prototype = {
myOtherMethod: function() {
// do something else
}
}
Note that you can define methods either using this keyword or via the prototype.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2019 05:07 PM
The Class "Class" is actually a Server Side Script Include, alas you cannot use in a UI Script.
You can see how it works by looking at the Script Include "PrototypeServer".
You'll need to use one of the two patterns mentioned by Slava.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022