Stop UI action to work if field is empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2022 07:49 AM
I have created a UI action to create another ticket. I need to make some fields mandatory to create that ticket. So if mandatory field is empty and when clicked on UI action that should not work. I need to make that in UI action script. Can anyone help me out this thing.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2022 07:54 AM
Hello ,
You can write an On click function and call your mandatory ode inside it like below
function checkMandatory() // call this function in onclick field
{
if(g_form.getValue('your field name')=="") //check if field is empty
{
alert("few fields are mandatory please fill");
return false;
}
}
Please mark my answer correct if it helped you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2022 10:20 PM
Hi Mohit,
I have tried this one it is showing alert but on click function is not working, no response is coming when I clicked on the UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2022 10:24 PM
Can you please share the code and screenshot of the entire UI action configuration ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2022 10:27 PM
Hi,
in the UI action script itself you can check if the mandatory fields are filled or not
If yes then proceed for ticket creation
If not then stop the form
something like this if your UI action is server side
if(current.u_field1 == '' || current.u_field2 == ''){
gs.addErrorMessage("Please fill mandatory fields");
}
else{
// your logic here
}
You can do something similar in client side UI action as well
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader