User should not allowed to submit form if Assignment group is empty

Deepak92
Tera Contributor

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;
}
}

 

find_real_file.png

can anyone help me what is the problem here ?

 

Thanks in advance 

 

3 REPLIES 3

Nick Fajardo
Tera Expert
Get value returns the actual value, not a true or false value. You want to check if the value is blank. That being said, this method of verification us completely bypassed if you know any JavaScript. At the very least, you should be using UI policies, maybe even data policies or business rules.

Allen Andreas
Administrator
Administrator

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!

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