how to disable the field when a form is opened in view mode
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 04:55 AM
I am just started working on service now, just wanted to disable the field when a form is opened in edit mode. is there any way to get it done?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 06:22 AM
can you share screenshots for the same i.e. in which mode are you referring?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 11:07 PM
Sorry, since i am new to this, i might not be able to explain it with right term. If you could see the attached picture, you could understand what i meant by edit scenario.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 11:17 PM
when you click New button it's an insert and when you open the record it's the existing record
you can differentiate this using onLoad client script and use g_form.isNewRecord() function
This will help you determine if it's a new record or an existing record
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
02-24-2023 12:19 AM
Its worked. Thanks a lot