onSubmit portal error message

Brad Shedd
Tera Contributor

Hey all,

How would I go about displaying an error in the service portal on submit when the value in one field is also in another field?

 

I have a field with a list of groups to request access too. (group_name)

The other field holds all the groups the requested for user is a member of. (members_groups)

If they try to request a group (Group Name) the user is already a member of  (Members Groups) on submit, I want an error to pop up so they have to fix it.

-or-

not display the groups already a member of in the (Group Name) field. Either way or both would be great knowledge for me.

 

Thanks

 

find_real_file.png

 

 

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you want to go the first route you would use an onSubmit client script where you grab the values of both of those variables. The group name value will be a 32 character sys_id and the members groups value will be a comma-separated list of sys_ids. You would just check to see if the value of the members groups variable contains the value of the group name variable, then return false, add a message to the form, and clear out the value of the group name. I would try writing this script and then let us know if you run into any issues. 

Your other option would be to use a reference qualifier on the group name field that doesn't allow the user to select a group they are a part of already. You can read more about reference qualifiers here: https://docs.servicenow.com/bundle/orlando-platform-administration/page/script/server-scripting/conc...

View solution in original post

1 REPLY 1

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you want to go the first route you would use an onSubmit client script where you grab the values of both of those variables. The group name value will be a 32 character sys_id and the members groups value will be a comma-separated list of sys_ids. You would just check to see if the value of the members groups variable contains the value of the group name variable, then return false, add a message to the form, and clear out the value of the group name. I would try writing this script and then let us know if you run into any issues. 

Your other option would be to use a reference qualifier on the group name field that doesn't allow the user to select a group they are a part of already. You can read more about reference qualifiers here: https://docs.servicenow.com/bundle/orlando-platform-administration/page/script/server-scripting/conc...