The CreatorCon Call for Content is officially open! Get started here.

why the OOB fields dont become read only

Alon Grod
Tera Expert

Im trying to make all the fields on the incident form as read only if the condition is met, but the OOB fields stay editable:

 

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);

        }

    }

}

 

Screenshot 2023-09-14 at 22.04.51.png

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

I'm assuming this is related to this question: Write ACL on the task table

 

You should continue with the Access Control method because this Client Script would NOT protect your records in a List view.

View solution in original post

3 REPLIES 3

Tony Chatfield1
Kilo Patron

Hi, assuming that you have checked and confirmed that your script is triggered, your syntax is correct and that your script is setting some fields on the form read only? Then based on your form screen shot still showing mandatory and editable fields I would guess that there are client scripts or Ui policies running after your onLoad client script.

I don't think this is sourced from official SNC documentation but it provides a nice graphical view of execution order.

Script Execution in ServiceNow: An In-Depth Look | LinkedIn

 

Also curious regarding your business drivers\requirements?

What will happen when there is no assignee and\or the task is new?
How are tasks managed if the assignee is absent?

 

Jim Coyne
Kilo Patron

I'm assuming this is related to this question: Write ACL on the task table

 

You should continue with the Access Control method because this Client Script would NOT protect your records in a List view.

BUT, to answer the question, yes, UI Policies are overriding the Client Scripts because they run after the onLoad Client Scripts.