Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Automatic setting of List type field (ReadOnly) by Client Script OnChange

d-aizawa
Kilo Sage

Hi.
I created a "u_Assigned to (TLAgent)" field in the Change Request table with the following content:
・Label:u_Assigned to (TLAgent)
・Value:u_assigned_to_tl_agent
・Type: List
・Read Only: True

 

"u_Assigned to (TLAgent)" field is automatically set, Created a Client Script "Set Assign" (On Change).

The content is the user in the "u_TLAgent" field of the Group registered in the Assignment Group,
It is set automatically.

If you set the "u_Assigned to (TLAgent)" field to ReadOnly,
If you do not save the record, the OnChange Client Script will not run,
Setting ReadOnly to False will automatically set the "u_TLAgent" field as expected.
Is this a characteristic of List type fields?
Thank you!

Client Script「Set Assign」(OnChange, trigger:Assignment Group)

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var tlSet = g_form.getReference('assignment_group', callback);
    function callback(tlSet) {
        g_form.setValue('assigned_to', tlSet.u_tl);
        g_form.setValue('u_assigned_to_tl_agent', tlSet.u_tl_agent);
		g_form.setReadOnly('u_assigned_to_tl_agent', true);
    }
}

 

Before Record Submit:

daizawa_0-1690790798508.png

Affter Record Submit:

daizawa_1-1690790886555.png

 

 

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@d-aizawa 

you are setting the value and making it readonly and after saving the value is present

Didn't get your exact question

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

Thank you for your response, Ankur.

I apologize for the poor wording and lack of explanation.

The "u_Assigned to (TLAgent)" field references the User table.

When the ReadOnly property of the "u_Assigned to (TLAgent)" field is set to False, it will behave as shown in the "After Record Submit" screenshot.

However, when the ReadOnly property of the "u_Assigned to (TLAgent)" field is set to True, it will take the form as shown in the "Before Record Submit" screenshot.

I would like to know if this limitation is due to the List type or if it can be resolved through customization.

Thank you!

@d-aizawa 

See the below responses I shared with example

That should help you understand the usecase

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

Thank you for your response.

Could you please specify what you mean by "responses I shared with example"?

Could you also post the URL in this thread?

Thank you very much.