- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 11:04 PM - edited 03-24-2024 11:13 PM
Hello Developers,
On sc_task, When 'Close Task' UI button is clicked, then it must check, If assigned_to & solution is filled or empty.
If empty then through an error msg. If filled then close the task.
I have wrote client script & called on Action name but it isn't working.
Please suggest if i have missed something.
function onSubmit() {
var action = g_form.getActionName();
var assignedTo = g_form.getValue('assigned_to');
var solution = g_form.getValue('u_solution');
if ((action == 'close_catalog_task') && ((assignedTo == '') || (solution == ''))) {
alert('Assigned To and Solution fields are mandatory. Please fill them out before closing the task.');
return false; // Prevent the UI action from executing further
}
// If both fields are filled, allow the UI action to proceed
return true;
}
}
Now as I'm editing it,
I have checked, Client callable.
Nothing is happening now when Close Task UI button is clicked. Stuck on same page.
Earlier it was closing without checking Assigned to & solution.
Not sure if gsftsubmit must be called.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 11:19 PM
you can handle this within UI action code itself and no client script required
check this link and it has solution
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 11:19 PM
you can handle this within UI action code itself and no client script required
check this link and it has solution
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 11:32 PM
I tried but no luck.
sc task is still getting closed with any alert or setting fields Mandatory.
function onCloseTask() {
var assignedTo = g_form.getValue('assigned_to');
var solution = g_form.getValue('u_solution');
if (!assignedTo || !solution) {
alert('Assigned To and Solution fields are mandatory. Please fill them out before closing the task.');
g_form.setMandatory('assigned_to', true);
g_form.setMandatory('u_solution', true);
return false; // Prevent the UI action from executing further
}
// If both fields are filled, allow the UI action to proceed
//return true;
gsftSubmit(null, g_form.getFormElement(), 'close_catalog_task'); //call action name
}
if (typeof window == 'undefined')
closeTask();
function closeTask() {
current.u_closure_code = 'Successful';
current.state = 3;
current.update();
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 11:35 PM