Variable Read Only

Bishal Sharma
Tera Contributor

Hi,

 

Can you help me to make below particular variable read only when state is closed complete or closed incomplete or closed skipped. (screenshot attached)

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi @Bishal Sharma 

This can be done using a Client Script on Catalog Task Table. You just need to write an On Change Client Script on Catalog Task Table on State Field and use the script below:

This client script will take care of both scenario when state changes also after you save the form it will validate for the state value to make it read only.

Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        var getState = g_form.getValue('state');
        if (getState == 3 || getState == 4 || getState == 7) {
            g_form.setReadOnly('variables.checkbox', true);
        }
        return;
    }
    if (newValue == 3 || newValue == 4 || newValue == 7) {
        g_form.setReadOnly('variables.checkbox', true);
    }

    //Type appropriate comment here, and begin script below

}

Screenshot for reference:

find_real_file.png

Result:

Script is an tested one in my PDI and will work for you as well for the query mentioned.

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

10 REPLIES 10

Instead of on submit, configure on load client script.

 

Regards,

Sachin

Same story with onLoad.

Try below code.

Also, use debugger in your client script debugging to debug further.

 

https://developer.servicenow.com/dev.do#!/learn/learning-plans/quebec/new_to_servicenow/app_store_learnv2_scripting_quebec_debugging_client_scripts

 

function onSubmit() {

var statevalue = g_form.getValue('state');

if((statevalue == '7') || (statevalue == '4') || (statevalue == '3'))
{
g_form.setReadOnly('Additional_software_requirements', true);
}


}

 

Regards,

Sachin

NIkhil Chaurasi
Tera Contributor

To access those variables, you need to use variables.VARIABLE_NAME & in UI Policy, mark it as read only.

g_form.setReadOnly(variables.VARIABLE_NAME);

shloke04
Kilo Patron

Hi @Bishal Sharma 

This can be done using a Client Script on Catalog Task Table. You just need to write an On Change Client Script on Catalog Task Table on State Field and use the script below:

This client script will take care of both scenario when state changes also after you save the form it will validate for the state value to make it read only.

Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        var getState = g_form.getValue('state');
        if (getState == 3 || getState == 4 || getState == 7) {
            g_form.setReadOnly('variables.checkbox', true);
        }
        return;
    }
    if (newValue == 3 || newValue == 4 || newValue == 7) {
        g_form.setReadOnly('variables.checkbox', true);
    }

    //Type appropriate comment here, and begin script below

}

Screenshot for reference:

find_real_file.png

Result:

Script is an tested one in my PDI and will work for you as well for the query mentioned.

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke