- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
yesterday
I had a customer requirement where we needed to hide a UI Action from the top form header and display it only at the bottom of the form.
UI Action:
When a UI Action is enabled as a Form button, ServiceNow automatically renders it in both the header and the bottom sections of the form.
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.addInfoMessage("TEST1");
/*
This line selects the UI Action button with the data-action-name value test from the form’s HTML using ServiceNow’s jQuery ($j)
*/
var ans = $j('[data-action-name="test"]')[0].hide();
g_form.addInfoMessage("Answer: " + ans);
}
Disable Isolate Script:
Turn off script isolation (set Isolate Script = false) so the client script can interact with the form’s DOM elements.
What happens when made true?
When Isolate script = true, ServiceNow:
- Runs the script in a sandboxed scope
- Prevents access to:
- Global objects
- DOM
- window
- $j / jQuery
- Allows only safe APIs like:
- g_form
- g_user
- GlideAjax
UI Action on the Target:
Result:
Happy Learning!!
- 66 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Direct DOM manipulation is not recommended. Instead, you should guide the customer on best practices and explain how the platform is intended to be used by end users.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is not a good practice, in fact this requirement should not be considered.
The availability of button at the top and bottom is a valuable feature in case the form is too big or the agent has to view the related records in the related list.
The bottom buttons provides the ease to agents.
I would emphasise the customers to align with the OOB features and reduce the technical debt wherever possible.
the script works for you now, but will it work forever as ServiceNow updates its versions?? I dont think so.