Making work notes mandatory if additional comments are empty and making additional comments mandatory if worknotes has some value.

Bhavna Chauhan
Tera Expert

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?

 

 

1 ACCEPTED SOLUTION

Bhavna Chauhan
Tera Expert

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:

find_real_file.png

OnChange Client Script will looks like this where field will be Addtional Comments:

find_real_file.png

Hence, it worked. 🙂

View solution in original post

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

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);

 

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."

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.

 

find_real_file.png

find_real_file.png

find_real_file.png

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,...

Jaspal Singh
Mega Patron
Mega Patron

 

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.