The CreatorCon Call for Content is officially open! Get started here.

UI Action to check a checkbox when click "Close Task" button on banner.

Mohammad10
Tera Contributor

I need to check one "checkbox" below before fulfiller click "close task" from banner to close the task.   

find_real_file.png

 

find_real_file.png

 

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

 

1 ACCEPTED SOLUTION

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

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

View solution in original post

19 REPLIES 19

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. 

Dhananjay Pawar
Kilo Sage

Hi,

Can you share the script here?

Thanks,

Dhananjay.

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.

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

}

 

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

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