Hide “Start Workflow” UI Action based on "AI Field and Change Type" in Change Request Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2025 11:05 AM
Hi All,
I’m working on a Change Request form where I have two key fields:
Ai (Backend name: ai) – a choice field with an option value: "yes" (which means "New to AI System")
Type (Backend name: type) – indicates the change type like Standard, Normal, etc.
Requirement:
If the user selects AI = yes and Type = Standard, then I want to hide the “Start Workflow” UI Action from the form. The UI Action button has a sys_id but I’m using the backend name start_the_workflow in scripts.
What I've Tried:
UI Action condition:
gs.hasRole('itil') && current.state == -5 && !(current.ai == 'yes' && current.type == 'standard')works after saving the form but not always on load.
Tried onChange scripts, UI Policies, and even $$(‘BUTTON’) based approaches.
My Goal:
Hide or disable the “Start Workflow” button as soon as the AI = yes + Type = standard is selected, without requiring a form save.
Also ensure it stays hidden on form reload if the condition still holds true.
Has anyone handled a similar use case or found a reliable way to dynamically control button visibility with these combined conditions?
Thanks in advance!
—CDJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2025 11:35 AM - edited 06-12-2025 11:57 AM
To my knowledge this type of functionality is not currently supported via default configurations but requires scripting to manipulate the DOM which is never recommended in ServiceNow.
Preferred functionality would be to simply set the condition on the UI Action for when to show the button. By default these conditions are evaluated on the server side as an onLoad function and will not dynamically update. This means that the user would have to change the fields and then click save for the condition to re-evaluate and show/hide the button.
If you want to try manipulating the DOM then you need to use a UI action with the conditions configured, On load and Reverse if false checked. Check Run scripts on the script tab and then configure the Execute if true and Execute if False. First you need to find all the buttons which requires having a button class name to search them by returning an array of all the buttons. Then perform a for() loop through all the buttons and perform an if() check on each one to see if the button's id matches the name of your UI Action. You then use .show() or .hide() appropriately to set visibility of the button.
Edit: Depending on the user experience you want you could also set an Onclick script for your UI Action that presented an error to the user and cancelled the action if your conditions were not met. A script like follows should work. Then just set your Onclick to execute the function.
Onclick: checkError()
function checkError() {
if (g_form.getValue('ai') !== 'yes' || g_form.getValue('type') !== 'standard') {
gs.addErrorMessage('Cannot Start the Workflow unless AI is set to "yes" and Type is set to "Standard."');
current.setAbortAction(true); //Not 100% sure this is the corrent method here, it depends on what/how your ui action executes. This would only stop server-side operations. If you are just stopping client-side operations the you would use 'return false;' instead.
}
}