How to make Incident Worknote OR Comment mandatory on Priority update

Evan McElfresh
Giga Guru

I have seen many articles related to making a Worknote mandatory when Incident Priority is updated, however my requirement is a little bit different:

I want EITHER a Worknote or Comment to fulfill the mandatory requirement.

 

We already have the Client Script seen in the SNOW Community for making only a Worknote mandatory:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '' || g_form.isNewRecord())
		return;
	else if (newValue == oldValue)
		g_form.setMandatory("work_notes", false);
	else
		g_form.setMandatory("work_notes", true);
}

And this was my stab at it, but it's not working.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '' || g_form.isNewRecord())
		return;
	if (newValue != oldValue)
		g_form.setMandatory("comments", true) || g_form.setMandatory("work_notes", true);		
	//else if (newValue == oldValue)
		g_form.setMandatory("work_notes", false) ||	g_form.setMandatory("comments", false);
}

 

Is there a better way to achieve this, or do I just need a small adjustment to the code?

Please mark this response as correct and/or helpful if it assisted you with your question.
2 REPLIES 2

Mohith Devatte
Tera Sage
Tera Sage

hello @Evan McElfresh ,

You need to have a condition in IF for that like and followed by else because if there is no else part the script wont understand what it should me make mandatory.Either it should be like below code or both mandatory.

Either ways you need an else part where the other field becomes mandatory 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '' || g_form.isNewRecord())
{
		return;
}
	if (newValue != oldValue)
		g_form.setMandatory("comments", true) 
else
g_form.setMandatory("work_notes", true);		
	
}

PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU

Thank you, but it's still not quite there.

 

The end result is that now Comments are mandatory, regardless whether there's a work note or not.

Please mark this response as correct and/or helpful if it assisted you with your question.