Should not be able to click any UI action when field is empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 07:09 PM
Have a requirement that whenever field is empty I should not be able to click any UI actions available on the workspace level,
When it has some value in it then only I should be able to click
May I know what are the methods can we achieve this requirement?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 08:28 PM - edited 02-20-2024 08:52 PM
Hi @XYD23
Yes, you can have a single UI Action that runs both Client-Side and Server-Side code. This is necessary sometimes, for example in the case where you want to check additional conditions or gather additional information from the user After he clicks the UI Action but Before you pass control back to the server.
- Yes, the way it is done is fairly convoluted because both Client-Side and Server-Side script is defined in the very same script block; so only Some of the code applies Some of the time
Use Below code:
function cancelPost(){
if (g_form.getValue('work_around') == ' '){
g_form.showFieldMsg('work_around','MY ALERT MESSAGE');
return false;
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'post_kb'); //MUST call the 'Action name' set in this UI Action
}
1. Check the "Client" checkbox. Normally UI Actions run only on the server, so this checkbox tells ServiceNow to run this on the client instead. But actually you will write both client-side and server-side code in the script block.
2. Define a function which will be called ONLY when the UI Action is clicked. (Not when it is rendered.)
3. Give your action a name. You will need to reference this name in the script itself. Basically, the UI Action script will "call itself", but the 2nd time it is invoked, it will be run on the server, not the client.
Follow thread it will be helpful or More details:-
client-side-and-server-side-code-in-one-ui-action-using
Please mark reply as Helpful/Correct, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 08:37 PM
Can you describe it more how and where exactly to use this code ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 09:20 PM
I should not be able click any of ui action!!
Not one

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 09:38 PM
Can you please share your code screenshot if it's possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 10:12 PM