Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Make assignment field mandatory on the incident form after saving (SOW)

suryaogeti1
Tera Contributor

once we select the assignment group and after saving the record in the incident form, the field needs to become read only in the service operations workspace. we can't change the assignment group. The below code is not giving the expected output

 

function onLoad() {

 

    if (g_form.isNewRecord()) {
        g_form.setReadOnly('assignment_group', false);
        return;
    }

 

   
    var assignmentGroup = g_form.getValue('assignment_group');

 

    if (assignmentGroup) {
        
        g_form.setReadOnly('assignment_group', true);
    } else {
        g_form.setReadOnly('assignment_group', false);
    }

 

 
    g_form.setReadOnly('assigned_to', false);
}
11 REPLIES 11

@suryaogeti1 

what debugging did you do?

How we would know the issue unless you debug

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

TharaS657398130
Giga Guru

The issue here isn’t really your logic, it’s that Service Operations Workspace doesn’t reliably honor traditional Client Scripts, so your onLoad script isn’t behaving as expected. The simplest and most reliable fix is to use a UI Policy instead. Create a UI Policy on the Incident table with the condition that the assignment group is not empty (and the record is not new), and set the assignment_group field to read-only. Most importantly, make sure the UI Policy is configured to apply to Workspace, otherwise it won’t work there. This approach avoids scripting issues and ensures that once the record is saved with an assignment group, the field becomes read-only and cannot be changed.