Issue in Business Rule

Service now11
Tera Contributor

Hi,

 

I have created a "Reopened" checkbox with a read-only condition in the Incident record and set its default value to false.

Scenario:

When the incident is in any state up to Resolved, the Reopened checkbox is unchecked (false). Once the user wants to reopen the incident (i.e., the state changes from Resolved to New, In Progress, or On Hold), the Reopened checkbox should be automatically checked (true) and set to read-only. Additionally, I want the Resolution Notes and Resolution Code fields to be cleared when the incident is reopened.

I have implemented this in Business Rule. But not getting solution. Can anyone help me on this?

 

Thanks,

Abirami

10 REPLIES 10

Viraj Hudlikar
Giga Sage

@Service now11  - As shared by Ankur it will work for you or do share your script so we can help you.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

Hi,

 

I have created an "onChange" client script that triggers when the state changes from "Resolved" to previous states like "New," "In Progress," or "On Hold." In this case, the "Reopened" checkbox should be checked (true). For all other states (such as "New," "In Progress," "On Hold," "Resolved," "Closed," or "Cancelled"), the "Reopened" checkbox is set to its default value of false. And also i have created "onLoad" client script for "Reopened " checkbox default value is false.

I am still not getting the expected solution. Could anyone help me identify what might be going wrong with this approach?. Here is my client script:

onChange Client script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    // Check if the script is not running during page load (isLoading should be false)
    if (isLoading || newValue === '') {
        return;
    }
    var state = g_form.getValue('state');
// When the state changes from 'Resolved' to 'New', 'In Progress', or 'On Hold'
    if (oldValue == 'Resolved' && (newValue == 'New' || newValue == 'In Progress' || newValue == 'On Hold')) {
        g_form.setValue('u_reopen', true); // Set the 'Reopened' checkbox to true
        g_form.setReadOnly('u_reopen', true); // Make it read-only (user cannot uncheck it)
    }
    // If the state is Resolved, uncheck the "Reopened" checkbox
    else (newValue == 'Resolved')
    {
        g_form.setValue('u_reopen', false);
        g_form.setReadOnly('u_reopen', true);
    }
   }
 
On Load client script"
function onLoad() {
    var state = g_form.getValue('state'); // Get the current state value
    var reopen = g_form.getValue('u_reopen');
 if (state == 'New' || state == 'In Progress' || state == 'On Hold') {
        g_form.setValue('u_reopen', false);
        g_form.setReadOnly('u_reopen', true);
    }
}
 
Thanks.

Hi @Service now11,

 

I believe that your onChange Client script is setting the 'u_reopen' field to True only when the State is changed from 'Resolved' to either New / In Progress / OnHold.

But after the State value change as you save the form, it will re-load and hence your onLoad Client Script will come into play, setting the 'u_repoen' field to False again.


I assume that after the Incident was first re-opened, you want the 'u_reopen' field to stay True indefinetly.

 

For this, you can update the if statement of your onLoad client script as

if (g_form.getValue('u_reopen'){
g_form.setReadOnly('u_reopen', true);
}

 

Hi @tanmay,

 

This script is not functioning as expected.

 

Thanks

Hello @Service now11 

 

Why to make complex by writing too many scripts. Let's make it simple.


As per your requirement, I tried this in my PDI, first created a true/false type field with name "Reopened" and made it read-only at dictionary level itself as looking in your requirement it will be auto populated when it met condition.

VirajHudlikar_0-1739091866860.png

Now a simple BR without much scripting as showcased below:

VirajHudlikar_1-1739091921842.png

VirajHudlikar_2-1739091952295.png

Now time for testing took a existing incident opened it and we can see clearly its In Progress so we change to Resolved.

VirajHudlikar_3-1739092089295.png

VirajHudlikar_4-1739092152187.png

 

Now we change state back to In Progress from Resolved and we can see Reopened field is true and resolution code and notes field is cleared.

VirajHudlikar_5-1739092244420.png

 

 

If you follow same thing, you will be able to achieve same. If still any issue do let me know.

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.