- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 12:33 PM
Hello,
I just want:
If user has closed completed a catalog task VIA ServiceNow THEN they should be required to enter EITHER worknote or additional comments.
- If user provides additional comments then worknotes are not required
- If user provides worknotes then additional comments are not required.
Solution: I was thinking to do this by client script but additional comments and worknotes label are not visible there, so i decided to create the Client Scrpt, but it also doesnt work. Cn anyone help?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 01:35 PM
Hello,
I have tried another way, first i made both additional comments and work notes mandatory using UI policy,where condition is State is Close Complete.
Then I create two onChange client scripts separetely: one for Additional comments and one for work notes:
OnChange Client Script will looks like this where field will be Worknotes:
OnChange Client Script will looks like this where field will be Addtional Comments:
Hence, it worked. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 03:45 PM
The trouble you're going to have here is that both of these fields on the sc_task table have the type of Journal, which means there can be more than one entry. So someone could put in a Work note, then save/update the task, then close it in a different step. If you just need to make sure a Work note or an Additional Comment was entered at some point on the task, you would create a before Update Business Rule on the sc_task table, with the Filter Condition
State changes to Closed Complete
The Script on the Advanced tab, would look like this:
(function executeRule(current, previous /*null when async*/) {
if (current.comments == '' || current.work_notes == '') {
current.setAbortAction(true);
gs.addErrorMessage('A Work note or Additional comment is required when closing a task');
}
})(current, previous);
If you want to make sure an Additional comment or Work note is added at the same time that the State is changed, the script would look like this:
(function executeRule(current, previous /*null when async*/) {
if(!current.comments.changes()){
if(!current.work_notes.changes()){
current.setAbortAction(true);
gs.addErrorMessage('You must add an Additional Comment or Work Note when changing the State to Closed Complete.');
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 05:18 AM
Apologies, I tried this, it doesn't work.
My requirement is "I want both work notes and additional comments to be mandatory at the same time, but if someone has added work notes first then additonal comments should become not mandatory and vice versa."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 09:49 AM
This Business Rule will prevent a Catalog Task from being Closed Complete if a Work note OR Additional comment are not added when the State change is attempted.
Note that since this is a Business Rule, the field label does not have the red *, and the State is not automatically reverted to the previous value, but the update is prevented. Using a Business Rule over a Client Script will ensure it is enforced any way that the task is attempted to be closed - UI, UI Action, API, List Edit,...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 05:27 AM
How will the task be closed? By UI Action or direcly by state change?
Also, share what was tried from your end as Client script.