g_form.setMandatory is not working in the code

Chaisai
Kilo Expert

Hello There,

 

 

On incident form i have a requirement like once state is changed from "Resolved" to "Assigned to"

have to ask for confirmation "Do you really want to re-open incident" and after clicking ok , comments should be mandatory and should show field message like comments are mandatory. I am able to achieve this with onchange client script but on field message is coming up but mandatory is not working wierdly, please find the code below. Any help is much appreciated.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading && oldValue!=6) //if oldvalue is not resolved  {
return;
}
g_form.clearValue('comments');

if(newValue==-3) //if new value is assigned 
{
var answr = confirm("Are you sure you want to reopen this incident?"); 
if(answr==true){ //working till here and going in loop
g_form.setDisplay('comments',true);
g_form.setMandatory('comments', true); //only mandatory is not working and even the fieldmessage also if this line commented field message is visible
g_form.showFieldMsg('comments','Please enter a comment when reopening an Incident', 'error');

}
else
{
return;
}
}
}

Note : on change field is selected as state 

13 REPLIES 13

Elijah Aromola
Mega Sage

Try changing the if to 

if (answer == "true")

vinothkumar
Tera Guru

Your script looks fine. Can you check whether it is related with known issue

 

https://hi.service-now.com/kb_view.do?sysparm_article=KB0687022

Any Workaround can be done here ? instance is on London itself.

vkachineni
Kilo Sage
Kilo Sage

Are there any UI policy actions that are making comments as not mandatory. can you confirm?

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

there are no such ui actions it is behaving same in my personal instance as well which is on New York