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

I have searched the UI Policies and Scripts can't find anywhere it is being set to mandatory or that the readonly status is being changed.  Configure Dictionary shows Read only and Mandatory are false:

Mark9_0-1715925418217.png

 

 

Lhora Alvarez
Tera Sage

@Mark9 

I noticed that the field name is not the same in both if and else code blocks.

In the IF code block, the field name is u_next_step.

But in the ELSE block, the incident table name is prepended.

 

Which of these 2 are correct?

Aside from that, your code should work.

That was just something I was trying. They should both just be u_next_step, but it still doesn't work. Thx.

@Mark9 

I think I might be misunderstanding something.

Can you tell me the technical name of the target table?

It's the Service Request [incident] table.