logo

NJP

How to make particular field read-only once the form saved only

New article articles in ServiceNow Community · Nov 27, 2024 · article

Use case:- To make particular field read-only once the the form is saved only based on some field conditions. (Not on load) Please note that on list view is not considered as it's already read-only.

Analysis:-

1. As there is no role specific condition, so ACL approach can't be used.

2. As per the use-case, it should not be made read-only on the form load hence UI Policy can't be used.

3. Considering above these points, let's try using Client script.

Solution:-

1. Write onLoad Client script on given table and use below script.

if (!g_form.isNewRecord())
 { 
// Check if its not a new record, record is saved

// Add the condition as per your need

 g_form.setReadOnly("field_name", true);

}

Conclusion:- This requirement can be achieved using g_form API isNewRecord() function from onLoad Client script.

View original source

https://www.servicenow.com/community/developer-articles/how-to-make-particular-field-read-only-once-the-form-saved-only/ta-p/3114364