How to make OOB visible if condition is met

Alon Grod
Tera Expert

Hi,

Im trying to make fields read only if condition is met, some of the fields that are not OOB become read only but the OOB fields dont become read only (like category,caller_id etc):

function onLoad() {
    //Type appropriate comment here, and begin script below
    var us = g_user.userID;
    if (us != g_form.getValue('assigned_to')) {
        for (var x = 0; x < g_form.elements.length; x++) {
            g_form.setReadOnly(g_form.elements[x].fieldName, true);
        }

    }

}

 

6 REPLIES 6

Peter Bodelier
Giga Sage

Hi @Alon Grod,

Are the fields that aren't readonly mandatory?
If so, you cannot set mandatory fields readonly, you'll have to set them not mandatory first.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

@Peter Bodelier still not working 

function onLoad() {
    //Type appropriate comment here, and begin script below
    var us = g_user.userID;
    if (us != g_form.getValue('assigned_to')) {
        for (var x = 0; x < g_form.elements.length; x++) {
			g_form.setMandatory(g_form.elements[x].fieldName, false);
            g_form.setReadOnly(g_form.elements[x].fieldName, true);
        }
		
    }

}

gurjot5
ServiceNow Employee
ServiceNow Employee

@Alon Grod Above rational is correct that OOB mandatory field might not be becoming read only , but if the client script is still not able to make the fields read only , it seems to be overwritten by UI policy on the form

 

Remember UI policies execute after client scripts , so some UI policy might be overwritting it , do consider checking the ui policies and their corresponding conditions and actions

 

Please mark the response as helpful if it solves the issue which you are facing

@gurjot5 does ACL override client script and ui policy?