- 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-23-2020 10:58 AM
yes this is what I thought, but was unable to to create working UI policy as I am a novice and need little bit more help creating UI policy.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2020 11:29 PM
Hi,
Can you share the script here?
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2020 11:41 PM
Hi,
In same onSubmit client script you can get Action name and based on that you can go ahead.
Sample script below.
function onSubmit() {
var actionName=g_form.getActionName();
if(actionName=='resolve_incident'){ // enter correct action name here
g_form.setValue('u_custom_field',true); // enter correct checkbox field name here
}
else{
g_form.setValue('u_custom_field',false); // enter correct checkbox field name here
}
}
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2020 09:43 AM
Hi Dhananjay,
Please find the code below: -
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') //If manager's approval required but not approved
{
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')//If team is not approved, task can be skipped but not closed.
{
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-23-2020 10:43 AM
Hi,
please try this
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').toString() == 'true')
{
if (g_form.getValue('approved_by_manager').toString() != 'true') //If manager's approval required but not approved
{
alert ('Managers approval required');
return false;
}
if (g_form.getValue('new_ms_team_approved').toString() != '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').toString() != 'true')//If team is not approved, task can be skipped but not closed.
{
alert ('You need to approve the team before closing this task otherwise select "closed Skipped".');
return false;
}
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader