What is UI Script and give me any example where you used UI Script. ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2018 04:04 AM
• What is UI Script and give me any example where you used UI Script.?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2022 11:01 AM
Hey Ram,
Let's understand what is the UI script first.
-I believe you must be aware of 'Script Include' in ServiceNow. if not, visit the below link.
-'UI Script' is just similar to 'Script Include', the only difference is 'Script include' we use to write server-side code and 'UI Script' we use to write client-side code. And the key point and similarity between both is we write those Functions or Scripts which can be reused multiple times.
-A developer need not to write the same code again for the similar kind of requirement. Instead a developer can call the function and the things done.
- 'UI script' functions can be called from any client-side script, 'Script Include' function can be called from any server-side script.
In simple words we can say UI-Script is a global client-side javascript code which we can call or run from other client side scripts, such as client scripts, UI Pages, UI Macro, HTML code etc.
Product doc for UI script- (check the demonstration of each file of UI-script form)
Note:
-Use caution when creating global UI scripts because they can impact performance. You cannot create a global UI script in a scoped application.
-UI type - if we want to call the UI script from ClienScript, then we need ‘Global’ field checked, for that UI type should be ‘Desktop’.
Let's work on very simple example- The key here is to understand the importance of UI script, not to achieve the task.
Use case - when a user creates any record such as incident, knowledge, problem, change etc. He should get the message on the form that how many records are created by him. e.g. if user has opened the incident form, user should get the message something like 'Total number of incident created by 'username' - 40'.
Solution - The logic is going to be the same, no matter which form or table he is working on, we just need a table name and based on 'table name' we can get the total number of records created by a user.
'Reason to use UI script' - we want this message on the form and when the user loads the form. So, we will be working at client-side and we know our logic is reusable for multiple tables.
Hence, we'll write a function into UI-script and then will call from client scripts.
Below client script, we have written for 'incident' table. For knowledge, problem records you can write it the similar code.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2022 02:46 PM