The CreatorCon Call for Content is officially open! Get started here.

How to make RITM variable read only on catalog task. When catalog task state is closed complete.

Obito
Tera Expert

How to make RITM variable (from a variable set) read only on catalog task. When catalog task state is closed complete.

Obito_0-1734359518162.png

 

3 REPLIES 3

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @Obito 

Please refer below threads:

https://www.servicenow.com/community/itsm-forum/ritm-variables-read-only-after-state-has-become-quot...

 

Please mark the answer as helpful and correct if helped. 

Kind Regards,

Ravi Chandra  

Ankur Bawiskar
Tera Patron
Tera Patron

@Obito 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

PARASHURAM R
Tera Contributor

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.