How to make RITM variable read only on catalog task. When catalog task state is closed complete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 06:32 AM
How to make RITM variable (from a variable set) read only on catalog task. When catalog task state is closed complete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 06:39 AM
Hello @Obito
Please refer below threads:
Please mark the answer as helpful and correct if helped.
Kind Regards,
Ravi Chandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2024 07:08 AM
you can use catalog UI policy which applies on Catalog Task View and condition as State = Close Complete
then use catalog UI policy actions
OR
you can use normal onLoad client script on sc_task and not catalog client script and use this
function onLoad() {
if (g_form.getValue('state') == 3) {
var variables = ['variable1', 'variable2', 'variable3'];
for (var i in variables)
g_form.setReadOnly('variables.' + variables[i], true);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 12:07 AM
You can use a client script to make the Ritm and Catalog Task variables read-only after the form is loaded. This script checks the task state, and if it's in a "Closed" state (e.g., Closed Complete or Closed Incomplete), it sets all editable fields to read-only.
function onLoad() {
// Set all variables to read-only once the form is loaded
setReadOnlyFields();
}
function onChange(control, oldValue, newValue) {
// Call this function when the state changes, to update read-only status
setReadOnlyFields();
}
function setReadOnlyFields() {
// Get the current state value from the form
var state = g_form.getValue('state');
// Define the states that should trigger read-only status
var closedStates = ['3', '4']; // Replace these with your actual state values for "Closed Complete" and "Closed Incomplete"
// Check if the current state is one of the closed states
if (closedStates.includes(state)) {
// Get all editable fields in the form
var fields = g_form.getEditableFields();
// Loop through the fields and set them to read-only
for (var i = 0; i < fields.length; i++) {
g_form.setReadOnly(fields[i], true);
}
} else {
// Optionally, reset the read-only status for non-closed states
var fields = g_form.getEditableFields();
for (var i = 0; i < fields.length; i++) {
g_form.setReadOnly(fields[i], false);
}
}
}
mark the answer as helpful and correct if helped.