User should not allowed to submit form if Assignment group is empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 11:09 AM
Hello Team,
we don't want users should submit the form if they havn't entered the assignment group
i have wrote a on submit client script but its not working
function onSubmit() {
//Type appropriate comment here, and begin script below
var assigment = g_form.getValue("assignment_group");
if (assigment != true) {
alert("you need to fill assigment group");
return false;
}
}
can anyone help me what is the problem here ?
Thanks in advance
- Labels:
-
Service Desk

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 11:29 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 11:39 AM
Hi,
Good overall advice from Nick above, but...many do use onSubmit Client Scripts and if that meets your need, then so be it. Anything with the client could potentially be overridden if people know JavaScript or browser developer tools.
Anyways...
function onSubmit() {
//Type appropriate comment here, and begin script below
if (g_form.getValue("assignment_group") == '') {
alert("you need to fill assigment group");
return false;
}
}
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 02:34 PM
Ok, javascript security is only one factor of this. Here are just a few other things to consider
- You're surprising the user entering the data additional, unmarked requirements. ServiceNow already provides the ability to mark fields as required based on certain conditions, and after doing so generates messages for for you.
- If the field isn't present on the form, the validation will always fail (even if the field is populated). For example, Assignment group isn't on the "Self Service" view of the incident form
- If someone changes the record via the list view or via the API, the rule doesn't get applied. So you've got data inconsistencies there.
- Why would the assignment group be always required? For example, you may not want an end-user creating the record to be just guessing. You may also have a scenario where a task might need to be edited several times before it's actually assigned to someone.
#1 is the biggest annoyance for me. So if you absolutely had to have this done via a client script, don't just validate onSubmit(). Mark the field as required via g_form.setMandatory("assignment_group", true) and do your users a favor