g_form.setMandatory is not working in the code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 05:59 AM
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
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 08:52 AM
can you try this code with basic stuff
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
/* commented out fow now
if (isLoading && oldValue!=6) //if oldvalue is not resolved {
return;
}*/
//This is the default
if (isLoading || newValue === '') {
return;
}
//g_form.clearValue('comments'); //commented out for now
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);//commented out for now
g_form.setVisible('comments', true); //try visible
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 {
g_form.setDisplay('state', oldValue); //set the state to old value;
return false;
}
}
}
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2019 11:12 PM
Already have tried the above code and it is going recursive and still no luck

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2019 11:45 PM
Hi Chaisai,
function onChange(control, oldValue, newValue, isLoading, isTemplate)
{
if (isLoading && oldValue!=6) //if oldvalue is not resolved
{ return;
}
if(newValue==-3) //if new value is assigned
{
var usrResponse = confirm('Are you sure you want to reopen this incident?');
if(usrResponse == true)
{
g_form.setDisplay('comments',true);
g_form.clearValue('comments');
//g_form.setValue('comments',''); //or try to use this instead of clearValue
g_form.setMandatory('comments', true); //if i am placing mandatory nothing is working
g_form.showFieldMsg('comments','Please enter a comment when reopening an Incident', 'error');
}
else
{
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 01:07 AM
Hi Sanket,
This seems to be a bug and as mentioned in other threads no workaround other than using a UI policy. Any other thoughts ?