On change of priority in incident form, making a custom field read-only/Set to "YES"

afreen shaik
Tera Contributor

RCA Required Attribute in the Incident form:

 

Requirement:
In the Incident form, there is a custom field labelled "Is RCA required" with two options: (a) Yes,

and (b) No.

afreenshaik_0-1731134863375.png

 

 

  • When the Priority field becomes “1-Critical” at any point in its lifecycle of incident , then “Is RCA required” field should automatically be set to “Yes” and become read-only , even  if the Priority field changes to “2-High” or “3-Moderate” or “4-Low”  even then “Is RCA required” field should be read-only.
  • If the Priority is directly set to other than “1-Critical”, then “Is RCA required” field should be editable. While trying to achieve this I’m facing some issues below is the approach I followed. Please review and suggest is there any alternative way to achieve this.

 

  • We have written a client script that checks the old and new values of the Priority field to determine if it has been set to “1-Critical.” If so, it sets the “Is RCA required” field to “Yes” and makes it read-only.

 

 

Script:

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading) {

 

         if (newValue === '1') {

        g_form.setValue('u_is_rca_required', 'yes');

        g_form.setReadOnly('u_is_rca_required', true);

    }

    // Check if oldValue was '1' and newValue is '2', '3', or '4'

    else if (oldValue === '1' && ['2', '3', '4'].includes(newValue)) {

        g_form.setValue('u_is_rca_required', 'yes');

        g_form.setReadOnly('u_is_rca_required', true);

    } // If the form is loading, we exit the function early.

    }

 

    // Check if the new value is '1' (P1 incident)

    if (newValue === '1') {

        g_form.setValue('u_is_rca_required', 'yes');

        g_form.setReadOnly('u_is_rca_required', true);

    }

    // Check if oldValue was '1' and newValue is '2', '3', or '4'

    else if (oldValue === '1' && ['2', '3', '4'].includes(newValue)) {

        g_form.setValue('u_is_rca_required', 'yes');

        g_form.setReadOnly('u_is_rca_required', true);

    }

}

 

 

 

 

afreenshaik_1-1731134863380.png

 

 

 

Please suggest the possible ways to achieve the above requested scenario @Ankur Bawiskar @Pranav Bhagat @Chuck Tomasi @Pradeep Sharma @Earl Duque @Laurel McDevitt 

 

1 ACCEPTED SOLUTION

Hello @afreen shaik 

After thoroughly analyzing the scenario and testing various approaches, I identified a solution to meet the requirement.

To implement this, follow these steps:

  1. Create a new field (e.g., RCA) on the Incident table. This field can be hidden on the form, and it will store a value (such as "Yes") whenever the Priority is set to Critical (P1).

  2. Set up a UI Policy to monitor the Priority field. When the Priority is "1", this policy will set the RCA field to "Yes".

  3. Create another UI Policy that checks if RCA is set to "Yes". If true, this policy will set the "Is RCA Required" field to "Yes" and make it read-only.

Using this approach, the RCA field will act as a persistent indicator of whether Priority was set to 1 at any point in the incident lifecycle, ensuring Is RCA Required is accurately set and remains read-only as needed.

Creating a new field(RCA) on incident table:

JuhiPoddar_3-1731344418741.png

UI policy in list view: 

JuhiPoddar_0-1731343443977.png

UI policy 1: configuration setup

Short description: set RCA if priority is critical

order: 100

Condition: priority is 1-critical

Reverse if false: unchecked

 

JuhiPoddar_1-1731343624031.png

 

 

function onCondition() {
    // Set RCA field to "Yes"
    g_form.setValue('u_rca', 'Yes');
}

 

 

 

UI policy 2: configuration setup

Short description: If RCA is set to Yes

order: 200

Condition: RCA is Yes

Reverse if false: unchecked

JuhiPoddar_2-1731343907671.png

 

function onCondition() {
    // Set u_is_rca_required field to "Yes"
    g_form.setValue('u_is_rca_required', 'Yes');
    // Make u_is_rca_required field read-only
    g_form.setReadOnly('u_is_rca_required', true);
}

 

 

 

"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

9 REPLIES 9

Juhi Poddar
Kilo Patron

Hello @afreen shaik 

 

The best way to approach this type of question is to use UI policy. This approach requires minimum scripting. Here is the attached screenshots to show the configuration setup in Ui Policy.

 

1) UI policy configuration setup:

JuhiPoddar_0-1731317231939.png

 

JuhiPoddar_1-1731317262619.png

 2)Ui policy Script:

function onCondition() {
    // Set RCA field to "Yes"
    g_form.setValue('u_rca', 'Yes'); //modify the field name
    // Make RCA field read-only
    g_form.setReadOnly('u_rca', true); //modify the field name
}

 

This will change the "Is RCA required" field to Yes and make it read only at any point the priority becomes critical-1. Once the RCA is set to Yes it will always be Yes and read only.

 

"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

Thank You
Juhi Poddar

 

Hello Juhi Poddar,

 

Thanks for your response.

The "Is RCA required" field should be set to "Read-only" and "yes" when the priority is "P1" at any point in the incident cycle. But the conditions are not as per the requirement.

 

Note: Even if the priority changes from P1 to P2  or P3 or P4

 

Best Regards,

Afreen Shaik

 

Hello @afreen shaik 

  • Thinking in a way that once the priority becomes p1 -> RCA is set to Yes.
  • So now if at any moment RCA is 'Yes' that means the priority has been to P1 before at any point of lifecycle.
  • Condition 2 checks that RCA is Yes, if it is Yes means it should never be changed to No and always be read only.

Condition 2 takes care of RCA if at any point the priority becomes P1. Even if the priority after that changes to P2, P3 or P4.

I would recommend to implement the solution once. This works in my PDI.

 

"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

Thank You
Juhi Poddar

 

Hello @Juhi Poddar 

 

I have implemented and tested the scenario you have mentioned. 

-> It is working when we first set  the Priority to "P1" and then change to other priorities(P2,P3).

-> But, when we first set the Priority to "P2" and then manually set to "Yes", at that time, it should not be read-only , as it is not the "P1" but it is becoming "Read-only" which is not expected.

 

Best Regards,

Afreen Shaik.

Hello @afreen shaik 

After thoroughly analyzing the scenario and testing various approaches, I identified a solution to meet the requirement.

To implement this, follow these steps:

  1. Create a new field (e.g., RCA) on the Incident table. This field can be hidden on the form, and it will store a value (such as "Yes") whenever the Priority is set to Critical (P1).

  2. Set up a UI Policy to monitor the Priority field. When the Priority is "1", this policy will set the RCA field to "Yes".

  3. Create another UI Policy that checks if RCA is set to "Yes". If true, this policy will set the "Is RCA Required" field to "Yes" and make it read-only.

Using this approach, the RCA field will act as a persistent indicator of whether Priority was set to 1 at any point in the incident lifecycle, ensuring Is RCA Required is accurately set and remains read-only as needed.

Creating a new field(RCA) on incident table:

JuhiPoddar_3-1731344418741.png

UI policy in list view: 

JuhiPoddar_0-1731343443977.png

UI policy 1: configuration setup

Short description: set RCA if priority is critical

order: 100

Condition: priority is 1-critical

Reverse if false: unchecked

 

JuhiPoddar_1-1731343624031.png

 

 

function onCondition() {
    // Set RCA field to "Yes"
    g_form.setValue('u_rca', 'Yes');
}

 

 

 

UI policy 2: configuration setup

Short description: If RCA is set to Yes

order: 200

Condition: RCA is Yes

Reverse if false: unchecked

JuhiPoddar_2-1731343907671.png

 

function onCondition() {
    // Set u_is_rca_required field to "Yes"
    g_form.setValue('u_is_rca_required', 'Yes');
    // Make u_is_rca_required field read-only
    g_form.setReadOnly('u_is_rca_required', true);
}

 

 

 

"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar