Client Script : check field

Abc 26
Tera Expert

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 .

8 REPLIES 8

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Abc 26 

g_form.isDisabled("FieldName") works for me. Calendar duration is read only so it returns true for that.

GunjanKiratkar_0-1669284000421.png

Output:-

GunjanKiratkar_1-1669284030553.png

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

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.

Hi @Abc 26 ,

It returns false for me if it is not read only. Please see below snapshot.

GunjanKiratkar_0-1669284499991.png

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

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"));

}