Unable to see any changes on Incident Form

neelamallik
Giga Contributor
function onSubmit() {

var isGroupChanged = g_form.isFieldChanged('assignment_group');
var isAssignedChanged = g_form.isFieldChanged('assigned_to');

var comments = g_form.getValue('u_journal_13');

if ((isGroupChanged || isAssignedChanged) && !comments) {
    alert('Please enter comments when reassigning the ticket');
    return false;

}
    return true;

}
 
can anyone please guide why unable to see any changes getting error like
 
neelamallik_0-1768543542995.png

 

1 REPLY 1

M Iftikhar
Tera Sage

Hello @neelamallik,

The mistake is that g_form.isFieldChanged() does not exist in ServiceNow client scripts, so your code errors out. You can achieve the same behavior by checking the .changed property of the field controls instead. 

// Check if the fields have been modified since the form loaded 
var groupChanged = g_form.getControl('assignment_group').changed; 
var assignedChanged = g_form.getControl('assigned_to').changed; 
var comments = g_form.getValue('work_notes'); 
 
if ((groupChanged || assignedChanged) && !comments) { 
   alert('Please enter work notes when reassigning the ticket.'); 
   return false; 
} 
 return true;

 If my response helped, please mark it as the accepted solution so others can benefit as well. 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.