multiple choice values read only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2024 03:20 AM
I want to set one of the choice variable value to read only based on the another variable in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2024 03:42 AM
Hello @Basina Akash
To establish a variable as read-only depending on another variable, you can employ a Catalog UI policy or a Catalog client script. In the OnChange client script, you can use the following code:
g_form.setReadOnly('variable_name', true);
If you wish to conceal a choice based on a variable, you can use the following line of code:
g_form.removeOption('fieldName', 'choiceValue');
Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Thanks & Regards,
Kartik Magadum
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2024 03:46 AM - edited ‎01-01-2024 03:47 AM
Hi @Basina Akash ,
as you want to make a field read only, when another field changes, the best way is to use an UI Policy and UI Policy Action, But as you said you want to make it using client script you can use on change client script and use below function
// below script is from product documentation @Basina Akash
// Create a Client Script on a table (e.g., incident) and paste this script
// Uncheck (set to false) the "isolate script" checkbox (not available by default)
// To add the isolate script checkbox to the form, configure form layout to add the checkbox
function onLoad() {
$("variable_map").querySelectorAll("item").forEach(function(item){
var variable = item.getAttribute("qname");
g_form.setReadOnly("variables."+ variable, true);
});
}
You can refer below link as well:
https://docs.servicenow.com/bundle/vancouver-api-reference/page/app-store/dev_portal/API_reference/G....
if my response helps you in fulfilling your requirement, please mark my answer as accepted solution or helpful @Basina Akash .
You can also refer this link for client script for further understanding @Basina Akash
Thanks & Regards,
S. Lakshmikanth Gupta.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2024 03:52 AM
Hi @Basina Akash ,
You can create a onChange script n use the below code in it
if (newValue == "some_value") {// use appropriate values here
// Set the choice variable to read-only
g_form.setReadonly(readOnlyVariable, true);// use proper backend name of the fields
} else {
// Set the choice variable to editable
g_form.setReadonly(readOnlyVariable, false);
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-01-2024 08:36 PM
I need only one of the choice field value not the entire variable , Only one of the value