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

Issue setting field to readonly

Mark9
Giga Expert

I'm trying to toggle the read-only property of the Next Step field (u_next_step) on the Service Record screen.  I have tried two approaches (UI Policy and Client Script) and neither approach works.  I know the code is being executed as I have added log statements to the console.  I also in the same code set sys_created_on to read-only (just to see that it works) and that field is being set to read-only while Next Step is not.  Both fields are initially editable in the form design.   When I create a new SR, the form loads and the Created field is grayed out but the Next Step field is not.

Here is the client script code:

function onLoad() {
    console.log('onLoad client script triggered');
    if (g_form.isNewRecord()) {
        console.log('This is a new record. The u_next_step field will be read-only.');
        g_form.setReadOnly('u_next_step', true);
        g_form.setReadOnly('sys_created_on', true);
    } else {
        console.log('Client Script: This is an existing record. Making the u_next_step field editable.');
        g_form.setReadOnly('incident.u_next_step', false);
        g_form.setReadOnly('sys_created_on', false);
    }
}

And here are the console statements
Mark9_0-1715919312656.png

 

 

I'm sure this should be really simple, but I can't figure it out. Any help would be greatly appreciated. Thx.



14 REPLIES 14

VaishnaviShinde
Kilo Sage

Hi @Mark9 ,

 

Change UI type of client script to All. Might be your Ui type is desktop.

 

Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

The UI Type is All

Jitendra Diwak1
Kilo Sage

Hi @Mark9,

 

Please check the field's dictionary wheteher mandatory checkbox is true.

 

Thanks

Jitendra

Please accept my solution if it works for and thumps up.

No it is not mandatory

Community Alums
Not applicable

Hi @Mark9 ,

There is no issue with code I checked in my PDI may be the issue is field sys_created_on and u_next_step may be mandatory from may be UI Policy or other Client Script or Configure Dictionary.

So that's why these 2 fields are not getting ReadOnly.

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak