Require User to Fill Out one of two Fields

jmiskey
Kilo Sage

On a Catalog Item that we are placing out on the Service Portal, we have a few fields (among many others):

- one is a "Multi-Line Text" field

- one is an "Attachment" field

The user is required to provide a description of the problem (multi-line text field) or attach a screen shot (attachment field).  So neither of these fields in Mandatory, but it is required that they populate at least one of these fields.

I assume I will probably need a Catalog Client Script to do this, but am unsure how to do that (especially the part of how to verify if there is an attachment or not).

Can anyone help?

1 ACCEPTED SOLUTION

@jmiskey write an on submit client script like this 

function onSubmit()
{
if(g_form.getValue('your first field name')! ='' || g_form.getValue('your attachment field name')!='' )
{
return true;
}
else
{
alert('please fill one of the fields');
return false;
}
}

try this it worked for me in my PDI 

if you try to do a getvalue of attachment variable it gives the sys_id of the attachment 

Please mark my answer correct if it helps you

View solution in original post

6 REPLIES 6

Mohith Devatte
Tera Sage
Tera Sage

hello @jmiskey

You can do one this instead of making the attachment field mandatory 

we can make the OOB attachment clip icon mandatory by checking one check box shown in below screenshot .

go to maintain items table and search for your catalog and then bring this "mandatory attachment " to list layout and make it true 

find_real_file.png

Please mark my answer correct if it helps you

 

Hmm. Either I am not understanding you, or you did not understand my original question.

I do NOT want to make the Attachment field mandatory (I know how to do that, that is easy to do).

Of the two fields listed on the Catalog Item:

- Description (multi-line text field)

- Screenshot (attachment field)

I want to require that they populate at least one of these two fields.

So, they cannot submit the form until they have either added something in the "Description" field, or they added an attachment to the "Screenshot" field.  They have to do at least one of these things, but are NOT required to do both.

 

@jmiskey write an on submit client script like this 

function onSubmit()
{
if(g_form.getValue('your first field name')! ='' || g_form.getValue('your attachment field name')!='' )
{
return true;
}
else
{
alert('please fill one of the fields');
return false;
}
}

try this it worked for me in my PDI 

if you try to do a getvalue of attachment variable it gives the sys_id of the attachment 

Please mark my answer correct if it helps you

Thank you!  I thought it would be more complex to check an attachment field.  I used your logic, but went the other way and check to see if they were both empty, and if so, cancel it then.

So my final code looks like this:

function onSubmit() {
	//If subcategory is "Web Issue", they must populate one of the URL fields

	//first check to see if web issue
	if(g_form.getValue('subcategory')=="web_issue"){
		//then check url fields and cancel submission if both blank
		if((g_form.getValue('url_steps')=='') && (g_form.getValue('url_screenshot')=='')){
			alert('You must fill out at least one of the last two fields (text or attachment)!');
			return false;
		}else{
			return true;
		}
	}else{
		return true;
	}
}

Thanks again for your help!