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

Hi Ankur,

 

I believe this script will work. This code will go for UI Action? How to run this script? 

 

Regards,

Mohammad

Thanks Ankur, what will be the condition for "UI Action"?

Will UI Action below will work?

Name: Close task
Table: sc_task
Order: 100
Action name: close_sc_task
Active: true
Form button: true
Condition: ?
Client: true
OnClick: Closetask()
Script:
Your Script above


Thanks,
Mohammad

Hi,

just keep the same condition which is present OOB

current.state.canWrite() && current.state != -5 && current.state < 3 && current.approval != 'requested'

Also update OnClick as : closeTask()

Regards
Ankur

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

Hi Ankur,

 

It is showing two "Close Task" buttons now.

find_real_file.png

 

Is it because we are using New York version? 

I tried override option too, did not worked. 

 

Hi,

Close task is on sc_task only

Regards
Ankur

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