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 06:17 AM
Try changing the if to
if (answer == "true")

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 07:03 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 07:11 AM
Any Workaround can be done here ? instance is on London itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 07:17 AM
Are there any UI policy actions that are making comments as not mandatory. can you confirm?
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 08:40 AM
there are no such ui actions it is behaving same in my personal instance as well which is on New York