How to make name value pair field read only ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 01:13 AM
Hi ,
I have tried onChange client script when field value is changed then name value pair field will be read only but after form has been submitted then field will be non read only , I have also tried UI Policy and Dictionary but it also not working , Please let me know .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 02:49 AM
Sorry I didn't follow you.
namevalue pair field will be readonly but after form has been saved then field will be non read only . ???
Can you explain again when the field has to be editable and when will it be non editable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 02:53 AM
once form has been saved field should be non editable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 03:02 AM - edited 10-18-2023 03:03 AM
You can try something like this
if (!g_form.isNewRecord()) {
g_form.setReadOnly('field name', true);
}
This basically checks if it is a new record, will only make it read only if it is not a new record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 02:56 AM
you are saying
once form has been saved field should be non editable -> so it means user should not edit on existing record
What happens when it's new record? It should be allowed for editing
you can use onLoad client script and determine if it's new record or not
function onLoad(){
if(!g_form.isNewRecord()){
g_form.setReadOnly('fieldName', true);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 03:12 AM
I have tried above code but when form has been saved then name value pair field will be editable , As per my requirement after form has been saved then name value pair field should be read only .