- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2020 11:08 PM
I need to check one "checkbox" below before fulfiller click "close task" from banner to close the task.
When I change task state, OnSubmit script works fine but when task is closed from banner, OnSubmit script do not work.
Please help
Thanks
Mohammad
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2020 11:34 PM
Hi,
2 approaches
1) make that variable as Mandatory for Catalog Task
OR
2) update the OOB UI action as below
Note: give the catalog item sys_id for whose Task you want to run this for
function closeTask(){
var catItemSysId = g_form.getReference('request_item').cat_item;
if(catItemSysId == 'Your Catalog Item Sys ID'){
var variableValue = g_form.getValue('checkbox_variableName');
if(variableValue == ''){
alert('Please select the checkbox before closing the task');
return;
}
}
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();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2020 11:27 PM
Hi Mohammad,
Can you provide more details on what you refer to when task is closed from banner? Please note that client script will not be triggered if the record is updated from a different table. In that case you need to validate this at server side via Before business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2020 11:29 AM
OnSubmit below code works fine Fig(steps 1-3) but when closing task using "Close Task" button (step 4) wont work.
here is the code:
function onSubmit()
{
// trim values of description and team name
var vDesc = g_form.getValue('team_description');
var vteamname = g_form.getValue('proposed_team_name');
vDesc = vDesc.trim();
vteamname = vteamname.trim();
g_form.setValue('team_description', vDesc);
g_form.setValue('proposed_team_name', vteamname);
//---------------------------------------------
var state1 = g_form.getValue('state');
// Check if State is Closed Complete
if(state1 == '3')
{
if (g_form.getValue('managers_approval_required') == 'true')
{
if (g_form.getValue('approved_by_manager') != 'true')
{
alert ('Managers approval required');
return false;
}
if (g_form.getValue('new_ms_team_approved') != 'true') //If managers approval is required and approved
{ // then make sure team is approved before closing task.
alert ('You need to approve the team');
return false;
}
}
//alert (state1);
if (g_form.getValue('new_ms_team_approved') != 'true')
{
alert ('You need to approve the team before closing this task otherwise select "closed Skipped".');
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2020 11:28 PM
Hi,
So before closing the task that checkbox should be set to true
you will have to update the code inside that UI action as well.
the onsubmit won't work when you click Close Task
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2020 11:34 PM
Hi,
2 approaches
1) make that variable as Mandatory for Catalog Task
OR
2) update the OOB UI action as below
Note: give the catalog item sys_id for whose Task you want to run this for
function closeTask(){
var catItemSysId = g_form.getReference('request_item').cat_item;
if(catItemSysId == 'Your Catalog Item Sys ID'){
var variableValue = g_form.getValue('checkbox_variableName');
if(variableValue == ''){
alert('Please select the checkbox before closing the task');
return;
}
}
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();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader