SK Chand Basha
Tera Sage
Tera Sage

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.

 

SKChandBasha_0-1767335127850.png

 

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

SKChandBasha_1-1767335635921.png

 

UI Action on the Target:

 

SKChandBasha_2-1767335670231.png

 

Result:

 

SKChandBasha_3-1767335723763.png

 

Happy Learning!!

 

 

 

 

Comments
Ankur Bawiskar
Tera Patron
Tera Patron

@SK Chand Basha 

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.

Deepak Negi
Mega Sage
Mega Sage

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.


Version history
Last update:
yesterday
Updated by:
Contributors