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:16 AM
Please refer below link :
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Regards,
Sanket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 06:26 AM
UI Action was already there and working this is to trigger when state value changed manually

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 06:35 AM
Try this :
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 usrResponse = confirm('Are you sure you want to reopen this incident?');
if(usrResponse == true){
g_form.setDisplay('comments',true);
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-23-2019 06:53 AM
Nope, no luck as issue is only with Making Comments Mandatory, Thanks!