Adding a Mandatory Close Notes to SCTASK

Brian Sorensen
Giga Guru

I just want to make sure this makes sense..

We have 1 Tier 2 who refuses to leave notes... super fun.  So when my Tier 1 team goes to check on a Catalog task and we see its been completed by this admin, we have no idea if he actually did what was asked.

I want to make it mandatory that when you press the CLOSE TASK button, you have to add notes

My thought is the following

1. Add the Close Notes field to the Form Design - this I can do
2. How do I make it Mandatory for them to fill it in when Close Task is clicked?

If I am not mistaken I do this
1. Configure UI Policy
2. Add new Policy - Condition State = Closed Complete - Close_notes Mandatory = True

Seems to work in Dev

Is there an easier way?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Brian Sorensen 

Using new UI policy on sc_task table to set Work Notes as Mandatory during State Changes to Closed Complete is the easiest way.

This would avoid touching the OOB "Close Task" UI Action

I would recommend using UI Policy based approach

1) Ensure for your UI Policy On Load checkbox is False

2) Also ensure if you wish to make this run only for some catalog items then add UI Policy condition as

Request Item.Cat Item [IS] Your Item Name

If you wish to use Script on the OOB UI Action then refer comments from Aman

Demo here:

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Prasad Pagar
Mega Sage
Hi Brian, You can do it directly in UI action Paste your UI script code I will help you to add code Thank you Prasad

Aman Singh_
Kilo Sage

Hi,

 

UI Policy is the easiest way, but if you want to accommodate the code within the UI Action itself then follow the thread.

Close task UI Action

 

Please mark Correct/helpful if applicable, thanks!!

Aman

i like this answer, but I do not know how I get into that Script?

Can you tell me how to access it?

 

I think I found it, but not sure
I was able to right click and go to UI Actions

Then filter down to on Form actions

Close Task

 

It has the following in it currently, so I am not sure if this is the right spot

function closeTask(){
g_form.setValue('state', 3);
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
updateTask();

function updateTask(){
current.state = 3;
current.update();
}

In the code you have already update as follows

function closeTask(){
if(g_form.getValue('close_notes') == '') {
try {
g_form.hideFieldMsg('close_notes');
} 
catch(e) {}
g_form.setMandatory('close_notes', true);
g_form.showFieldMsg('close_notes', getMessage('Please enter supporting close notes when closing the change task'), 'error');
return false;   // Abort submission
}
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
updateTask();

function updateTask(){
current.state = 3;
current.update();
}