UI scripts
-
- UpdatedAug 1, 2024
- 2 minutes to read
- Xanadu
- Building applications
UI scripts provide a way to package client-side JavaScript into a reusable form, similar to how script includes store server-side JavaScript. Administrators can create UI scripts and run them from client scripts and other client-side script objects and from HTML code.
UI scripts are not supported for mobile.
Global UI scripts
You can create a UI script and designate it as global, which makes the script available on any form in the system. You cannot create a global UI script in a scoped application.
You can mark a UI script as Global to make it available on any form in the system. For example, you can create a UI script that has a function helloWorld(), and has the Global field checked:
After you create this global UI script, you can call the helloWorld() function from any client script or UI policy you write.
Create a UI script
Create a UI script to define reusable client-side JavaScript code.
Run UI scripts
Follow these guidelines when running UI scripts.
Run a UI script from a form
To run a UI script on a form, Create a formatter and add it to a form. In the associated UI macro, include a
g:requires
tag and specify the name= parameter as
the name of the UI script followed by the .jsdbx extension. Add the formatter on the form
view.
This code ensures that the definitions and results of the UI script are immediately available in the browser.
Call a UI script in HTML
To run a UI script from HTML code, use the <script>
tag and specify the
src=
argument as the API name of the UI script followed by the .jsdbx
extension. For example, include the UI script named CoolClock with this
code:
Call a UI script from client-side code
Access UI scripts from within client-side code using the g_ui_scripts global object. For more information, see GlideUIScripts - Client.