
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2020 02:27 PM
Currently when our cases are cancelled the state changes to Awaiting Acceptance. We don't want the requester to be able to reject a cancelled case. We want the case to remain as cancelled and read-only. I am very new to ServicNow and I have zero experience writing script. don't know if I need to change a UI Action, UI Policy or Workflow. Do you always have to write script for UI Actions? It would be nice if I could use a condition builder.
This is the UI Action script for Cancel
State 7 = Cancelled
State 20 = Awaiting Acceptance
Do I just need to change the highlighted state to 7 or remove line 33 altogether?
Also, once a case is cancelled we want the case to be read-only and not able to reopen it.
Thank you in advance for anyone that can help me out.
Solved! Go to Solution.
- Labels:
-
Workflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2020 07:41 AM
Hi Suzanne,
I believe your UI action to cancel the case is setting the state to Awaiting acceptance and you want your form to be read only once the state is cancelled. If my understanding is correct then first let me explain you the complete script so that it will be easy for you to understand what piece of code does what.
When UI Action is being clicked function cancelcase() is being called which starts from the Line 1.
Line 2-7: It checks for the field value of 'u_resolution_code' and 'u_resolution_notes' if any of the field is empty(do not have any value) it sets both the field mandatory and returns false which restricts the form to get submitted.
if both the fields 'u_resolution_code' and 'u_resolution_notes' has values then:
Line 23: It sets the value of field 'comments' same as 'u_resolution_notes'.
Line 25-26: If the field 'skip_automatic_user_acceptance_state' has value then it sets the state to value 7(Cancelled as mentioned by you in your original question)
Line 27-38: If 'skip_automatic_user_acceptance_state' do not have any value then the value of 'sla_suspended' will be set as true and the state will be set as 20(Awaiting acceptance as mentioned in your original question) and the field 'sla_suspended_on' value is set as the current system time.
Line 39: Form is being saved with the fields value.
So I believe the script is working as per the definition, your record do not have any value in the field so it's entering into else loop and setting the state value as 20(Awaiting acceptance). I would request you to try with some value in the field 'skip_automatic_user_acceptance_state' and I believe the UI Action will set the state as cancelled, Also, get back to the business and get clarified what process is needed whether they are going to use the field 'skip_automatic_user_acceptance_state' or not.
If they will use the field then your script is well and good. If in the case the business do not wants to use the field then you can just simply modify the code and set the values at once instead of validating the field 'skip_automatic_user_acceptance_state'.
Now, coming to the second stuff, the read only of the fields can be done in 3 different way, ACL, UI Policy and Client Script. The best solution for you would be ACL. I believe there will be an existing ACL for create operation just go and add the condition as State is not cancelled and you are done. If not create a new one by selecting table as target table and field as None.
Please find the sample snipped below:
In the above snipped I provided the access to edit the field to ITIL users if the state is not canceled.
Kindly mark my answer as Correct and helpful based on the Impact.
Regards,
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2020 10:00 PM
Hi Suzanne,
If I understand your issue correctly, you want to achieve 2 things
1. Show the case state as canceled when it is canceled (It was earlier showing as Awaiting Acceptance)
If my assumption is correct, as you mentioned modify line 33 to have state 7 instead of 20. Once you make this change, going forward all canceled cases will show as canceled instead of Awaiting Acceptance.
2. You want to make the state field readonly if the state is Canceled.
You can achieve this in multiple ways. You can create a client script and make the field readonly if the state is canceled. Or you can create a write ACL on this field and in condition specify state Is Not Canceled.
Please mark answer helpful or correct if it helps or resolves your issue.
Thanks
Ashok

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2020 07:41 AM
Hi Suzanne,
I believe your UI action to cancel the case is setting the state to Awaiting acceptance and you want your form to be read only once the state is cancelled. If my understanding is correct then first let me explain you the complete script so that it will be easy for you to understand what piece of code does what.
When UI Action is being clicked function cancelcase() is being called which starts from the Line 1.
Line 2-7: It checks for the field value of 'u_resolution_code' and 'u_resolution_notes' if any of the field is empty(do not have any value) it sets both the field mandatory and returns false which restricts the form to get submitted.
if both the fields 'u_resolution_code' and 'u_resolution_notes' has values then:
Line 23: It sets the value of field 'comments' same as 'u_resolution_notes'.
Line 25-26: If the field 'skip_automatic_user_acceptance_state' has value then it sets the state to value 7(Cancelled as mentioned by you in your original question)
Line 27-38: If 'skip_automatic_user_acceptance_state' do not have any value then the value of 'sla_suspended' will be set as true and the state will be set as 20(Awaiting acceptance as mentioned in your original question) and the field 'sla_suspended_on' value is set as the current system time.
Line 39: Form is being saved with the fields value.
So I believe the script is working as per the definition, your record do not have any value in the field so it's entering into else loop and setting the state value as 20(Awaiting acceptance). I would request you to try with some value in the field 'skip_automatic_user_acceptance_state' and I believe the UI Action will set the state as cancelled, Also, get back to the business and get clarified what process is needed whether they are going to use the field 'skip_automatic_user_acceptance_state' or not.
If they will use the field then your script is well and good. If in the case the business do not wants to use the field then you can just simply modify the code and set the values at once instead of validating the field 'skip_automatic_user_acceptance_state'.
Now, coming to the second stuff, the read only of the fields can be done in 3 different way, ACL, UI Policy and Client Script. The best solution for you would be ACL. I believe there will be an existing ACL for create operation just go and add the condition as State is not cancelled and you are done. If not create a new one by selecting table as target table and field as None.
Please find the sample snipped below:
In the above snipped I provided the access to edit the field to ITIL users if the state is not canceled.
Kindly mark my answer as Correct and helpful based on the Impact.
Regards,
Alok