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:01 AM
Hi @Abc 26
g_form.isDisabled("FieldName") works for me. Calendar duration is read only so it returns true for that.
Output:-
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:04 AM - edited 11-24-2022 02:04 AM
Hi Gunjan Kiratkar ,
Can you please try for the field which is not read-only and please let me know whether you are getting the same result or different.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 02:08 AM
Hi @Abc 26 ,
It returns false for me if it is not read only. Please see below snapshot.
Please share your code. So that I can assist further.
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:14 AM
Hi @Gunjan Kiratkar ,
Please find the script below , it is onload client script on change request.
function onLoad() {
var readOnlyField = g_form.isDisabled('state'); // Check if state is read only
var getState = g_form.getValue('state') == '-3'; //Authorize state
if (readOnlyField && getState)
g_form.showFieldMsg("state", getMessage("Change is approval state"));
}