Client Script : check field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 01:48 AM
Hello Experts,
I want to check whether the field is read only or not ,based upon i want to display a field message.
I have tried below g_form methods and it does not work.
g_form.isReadonly()
g_form.isDisabled()
Please help .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 02:17 AM
Hi @Abc 26 ,
use below code
function onLoad() {
var readOnlyField = g_form.isDisabled('state'); // Check if state is read only
if (g_form.getValue('state') == '-3') {
var getState = g_form.getValue('state'); //Authorize state
}
if (readOnlyField && getState)
g_form.showFieldMsg("state", getMessage("Change is approval state"));
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 02:20 AM - edited 11-24-2022 02:21 AM
Or else below for last line
g_form.showFieldMsg('state','Change is approval state','info');
function onLoad() {
var readOnlyField = g_form.isDisabled('state'); // Check if state is read only
if (g_form.getValue('state') == '-3') {
var getState = g_form.getValue('state'); //Authorize state
}
if (readOnlyField && getState)
g_form.showFieldMsg('state','Change is approval state','info');
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 03:04 AM
Hi Gunjan,
The issue here is i am always getting readOnlyField as false even when the state is readonly.
var readOnlyField = g_form.isDisabled('state')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 03:11 AM
Hi @Abc 26
How do you make that state field read only ? OnLoad of any client script ?