How to make all fields not editable when state is one of the below ones

phr
Tera Contributor

Hi All,

 

I have a requirement where whenever an RITM is closed with:
- Closed Rejected 
- Closed Skipped 
- Closed Incomplete 
Several fields in the RITM remain editable. How do i make these fields not editable?

phr_0-1715772000657.png

 

 

4 REPLIES 4

Sohail Khilji
Kilo Patron
Kilo Patron

Its not clear can you detail it more ?


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Hi @Sohail Khilji 

 

Whenever the state is set to "Closed Rejected", "Closed Skipped" and "Closed Incomplete " on the RITM. The reaming fields on the RITM also should also be read only (ie not editable).

How to achieve this.

For this you need to create a OnLoad Client script as below:

 

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

if(stat =='8' || stat=='10' || stat== '11'){ // pass the values of all 3 states here
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);

☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Mark Manders
Mega Patron

Create an onLoad client script like this (apply your states and the correct statement in the 'if')

 

function onLoad() {
    // Define the states that should trigger read-only mode. These are examples (from incident):
    var closedState = '7'; // Example  for "Closed"
    var canceledState = '8'; // Example  for "Canceled"

    // Get the current state of the form
    var currentState = g_form.getValue('state');

    // Check if the current state is Closed or Canceled
    if (currentState === closedState || currentState === canceledState) {
        // Get all fields on the form
        var fields = g_form.elements;

        // Loop through all fields and set them to read-only
        for (var i = 0; i < fields.length; i++) {
            g_form.setReadOnly(fields[i].fieldName, true);
        }
    }
}

 

I used it for incident, so you need to make sure your states are applied.
You can also adjust a read acl (on state x, no writing on the record), but you need to make sure no other field ACL is counteracting that. Or you can go for a ui policy and add all of your fields manually to the actions.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark