Prevent commenting on a closed HR case

Fin Nguyen
Tera Guru

Hi Community!

I have made a br Before - Update to prevent user comments on a closed HR case (active is false)

ThinhNguyen_0-1698739475292.pngThinhNguyen_1-1698739486336.png

AbortAction and ErrorMessage are added.

It is working perfectly in the Portal view, because every time we hit the Post button, the form will be also reloaded, and the error message appears.

ThinhNguyen_2-1698739694954.png

But in the Native UI view, every time we hit the Post button, comments are not added, but the error message does not appear until we reload the form or go to another place.

ThinhNguyen_3-1698739954179.png

So I am finding a solution to have the same behavior as the Portal view to increase the user experience, it means every time we hit the Post button in the Native UI view, the error message appears at the same time, same page.

 

Thank you!

Regards,
Fin Nguyen
1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @Fin Nguyen 

The most effective strategy would involve establishing an ACL Write to restrict users from updating Closed Cases. I'm just wondering why we permit users to add comments and then attempt to prevent this action afterward.

 

You can find similar OOTB concept in the Incident table.

URL: https://<instance_name>/sys_security_acl_list.do?sysparm_query=name%3Dincident%5EORname%3Dincident.*...

 

After define the ACL, if necessary you can create one more OnLoad Client Script to show the message on the form of Closed Cases.

 

Cheers,

Tai Vu

View solution in original post

3 REPLIES 3

Community Alums
Not applicable

Hi @Fin Nguyen ,

I have faced the same, that's the behavior in native UI!!
Refer to this thread : https://www.servicenow.com/community/developer-articles/how-to-show-warning-messages/ta-p/2330020

 

Vishal Birajdar
Giga Sage

Hi @Fin Nguyen 

 

With addition to your Business rule , you can write onChange client script on "Additional comments" field : 

 

Type : onChange

Field : Additional comments

 

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
       g_form.clearMessages();
     return;
    }

    var state1 = g_form.getValue('state');  //you can use your condition fields (like active)
    if (state1 == 3) {
        g_form.clearMessages();
        g_form.addErrorMessage('Case has been closed');
    }


}

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Tai Vu
Kilo Patron
Kilo Patron

Hi @Fin Nguyen 

The most effective strategy would involve establishing an ACL Write to restrict users from updating Closed Cases. I'm just wondering why we permit users to add comments and then attempt to prevent this action afterward.

 

You can find similar OOTB concept in the Incident table.

URL: https://<instance_name>/sys_security_acl_list.do?sysparm_query=name%3Dincident%5EORname%3Dincident.*...

 

After define the ACL, if necessary you can create one more OnLoad Client Script to show the message on the form of Closed Cases.

 

Cheers,

Tai Vu