- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 10:53 PM
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.
- 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);
}
}
Please suggest the possible ways to achieve the above requested scenario @Ankur Bawiskar @Pranav Bhagat @Chuck Tomasi @Pradeep Sharma @Earl Duque @Laurel McDevitt
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 09:04 AM
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:
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).
Set up a UI Policy to monitor the Priority field. When the Priority is "1", this policy will set the RCA field to "Yes".
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:
UI policy in list view:
UI policy 1: configuration setup
Short description: set RCA if priority is critical
order: 100
Condition: priority is 1-critical
Reverse if false: unchecked
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2024 12:05 AM - edited 11-09-2024 12:08 AM
Hello @afreen shaik , I am not sure to understand why you remove the return syntax in the "is loading" code section. I think somethink like the following code will do the trick.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '' || oldValue == '1') {
if (newValue == '1') {
g_form.setValue('u_is_rca_required', 'yes');
g_form.setReadOnly('u_is_rca_required', true);
}
return;
}
if (newValue == '1') {
g_form.setValue('u_is_rca_required', 'yes');
g_form.setReadOnly('u_is_rca_required', true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 10:18 PM
Hello Jean,
Thanks for your response.
I have tried your code, but it only works when the 'Priority' is 'P1'. When it changes from 'P1' to 'P2' or from 'P2' to 'P3,' it does not make the custom field("u_is_rca_required") read-only.
The requirement is to set the custom field to read-only and "Yes" whenever the 'Priority' is 'P1' at any point.
Best Regards,
Afreen Shaik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2024 12:33 AM
Hi @afreen shaik ,
You can use below script, i have tested it, working well.
if (g_form.isNewRecord() && newValue == '1') {
g_form.setValue('u_is_rca_required', 'software');
g_form.setReadOnly('u_is_rca_required', false);
} else if (oldValue == '1' || newValue == '1') {
g_form.setValue('u_is_rca_required', 'software');
g_form.setReadOnly('u_is_rca_required', true);
} else {
g_form.clearValue('u_is_rca_required');
g_form.setReadOnly('u_is_rca_required', false);
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2024 11:05 PM
Hello afreen shaik,
You can use client script.
client script type: Onchange
Field Name: priority
Client script:
Best Regards,
Sufiyan Murshad