- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 08:37 AM
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)
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2022 04:55 AM
Hi
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:
Result:
Script is an tested one in my PDI and will work for you as well for the query mentioned.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 09:17 AM
Instead of on submit, configure on load client script.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 09:39 AM
Same story with onLoad.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2022 09:57 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2022 03:59 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2022 04:55 AM
Hi
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:
Result:
Script is an tested one in my PDI and will work for you as well for the query mentioned.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke