To make additional comments mandatory when state set to canceled (should run in both views)

rishabh31
Mega Sage

Dear Team,

 

In the Incident record, when the field State is set to 'Canceled', then want to make the field 'Additional Comments (comments)' mandatory and restrict the form submission/updation/save and throw an error message at top.

 

This should work in both views (Portal view and Standard form view)

 

I tried through client scripts, UI Policies but no luck.

 

Kindly help with the steps and script to get this resolved.

 

Thanks

 

 

18 REPLIES 18

SunilKumar_P
Giga Sage

Hi @rishabh31, You can try the below OnChange client script to make the additional comments mandatory when the Incident state is set to Cancelled.  You need to make sure the Field Name is set to 'State' on the Client Script.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (newValue == 8 ) { //Cancelled
        g_form.setMandatory('comments', true);
    } else {
        g_form.setMandatory('comments', false);
    }
}
 
Regards,
Sunil

hydergani-Brill
Tera Contributor

UI Policy work with order 300 

rashijain82
Tera Contributor

 I am facing the same issue.

Simran Gadodiya
Mega Sage

Hi @rishabh31 

You can try onChange Client Script when the State changes:

 

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

 

If this resolve your problem please mark it as helpful and accept the solution.

Thank You!