In the Risk Register I wants to add new field and it might be read only when user create new Risk

Nayanja
Tera Contributor
function onLoad() {
    if (g_form.isNewRecord()) {
        g_form.setReadOnly('u_threat_actor', 'false');

 

    } else {
        g_form.setReadOnly('u_threat_actor', 'true');

 

    }

 

}
checked that it is overriding the business rules, client scripts, and UI policies.
5 REPLIES 5

Vishal Jaswal
Giga Sage

Hello @Nayanja 

 

Try below:

 

function onLoad() {
if (g_form.isNewRecord()) {
// Only set read-only if no other logic is already applied
if (!g_form.isReadOnly('u_threat_actor')) {
g_form.setReadOnly('u_threat_actor', false);
}
} else {
// check existing configurations before setting read-only
if (!g_form.isReadOnly('u_threat_actor')) {
g_form.setReadOnly('u_threat_actor', true);
}
}
}


Hope that helps!

Ankur Bawiskar
Tera Patron
Tera Patron

@Nayanja 

if the field is readonly because of ACL then you cannot override it

what's happening now when you are using that script?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar when I was opening a risk register form that "Treat actor" field shown as read-only

@Nayanja 

is there any field level write ACL or UI policy which is making it readonly?

what debugging did you do?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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