On submit validation

VALLUB
Tera Contributor

Hi Community,

 

I have one requirement, In form level having requestor for filed and assignment group filed, requestor field taking the user table and in assignment group filed taking the group table, and in my requirement they ask me to create one new check box filed which is assign to me and if user check the check box which is assign to me and user is the member of that group then the form should submits and if user is not member of that group then form should not be submitted.

 

Thanks in advance!

2 REPLIES 2

Brian Lancaster
Tera Sage

I'm not sure I understand what you are asking here. Please take a look at this article on how to write a quality question.

https://www.servicenow.com/community/servicenow-ai-platform-articles/10-tips-for-writing-a-quality-c...

John Gilmore
Giga Guru

While its not clear exactly where you are trying to do this if we assume its a catalog item or record producer then you could simply add a catalog client script as follows. A similar onSubmit script could be used any where but the syntax/method for accessing the variables might change slightly...

 

function onSubmit() {
	var assignmentGroup = g_form.getValue('variable_name'); //replace variable_name with the correct name of the assignment group variable
	if (g_form.getValue('check_box_variable') == true) { //replace check_box_variable with the correct name of the assign to user check box variable
		if (gs.getUser().isMemberOf(assignmentGroup) {
			return true;
		} else {
			alert("You are not a member of the assigment group."); //this message will be shown to the user when the validation fails, word it appropriately.
			return false;
		}
	} else {
		return true;
	}
}