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);
}
8 REPLIES 8

suryaogeti1
Tera Contributor

but i needs to work after saving the record, when we use ui policies, it is going to read only state as soon as we selected but that's not, we are expecting

@suryaogeti1 

try to give some timeout for your script

Ensure UI Type - ALL

function onLoad() {
    applyAssignmentGroupState();

    setTimeout(function() {
        applyAssignmentGroupState();
    }, 200);
}

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

    var assignmentGroup = g_form.getValue('assignment_group');
    g_form.setReadOnly('assignment_group', !!assignmentGroup);
    g_form.setReadOnly('assigned_to', false);
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

it is not working in service operations workspace

@suryaogeti1 

what debugging did you do?

UI type - ALL?

Global checkbox checked on client script?

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