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

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

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.

OnSubmit below code works fine Fig(steps 1-3) but when closing task using "Close Task" button (step 4) wont work. 

 

 find_real_file.png

 

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


}

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

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