Client Script g_form.setReadOnly() not working.

JavaScriptMaest
Giga Contributor

g_form.setReadOnly() method not working when I run it through Client Script, but it works when I run the same on the JavaScript Executor(Ctrl + Alt + Shift + J), is there a way to debug and know what is stopping my Client Script code to not work on setting the field read only. 

The Client Script is:

 

find_real_file.png

1 ACCEPTED SOLUTION

Are there any UI policies that are conflicting with your client script?

View solution in original post

24 REPLIES 24

snow123
Kilo Contributor

Hi Rahul,

                 Put the  g_form.setReadOnly('item', true); after completing the first brace. It will work both mandatory and readonly function. 

 

Regards,

Suresh.

Elijah Aromola
Mega Sage

What UI type is your client script set to?

Desktop

I'm not sure if ServiceNow supports forEach in scripts. Can you try converting it to a for loop? 

for( var i = 0; i < fieldsArray.length; i++) {
    g_form.setReadOnly(fieldsArray[i], true);
}

maicol99
Tera Contributor

Check if your client script is in the same scope of the field.