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

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

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

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')

 

Hi @Abc 26 

How do you make that state field read only ? OnLoad of any client script ?


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