Assigned to should be mandatory when closing sc_task via UI button

Naveen87
Tera Guru

Hello Developers,

 

On sc_task, When 'Close Task' UI button is clicked, then it must check, If assigned_to & solution is filled or empty.

If empty then through an error msg. If filled then close the task.

I have wrote client script & called on Action name but it isn't working.

Please suggest if i have missed something.

Naveen87_0-1711346628075.pngNaveen87_1-1711346643444.png

 

function onSubmit() {

    var action = g_form.getActionName();
    var assignedTo = g_form.getValue('assigned_to');
    var solution = g_form.getValue('u_solution');
	
    if ((action == 'close_catalog_task') && ((assignedTo == '') || (solution == ''))) {
        alert('Assigned To and Solution fields are mandatory. Please fill them out before closing the task.');
        return false; // Prevent the UI action from executing further
    }
    // If both fields are filled, allow the UI action to proceed
    return true;
}
}

 

 

Now as I'm editing it,

I have checked, Client callable. 

Nothing is happening now when Close Task UI button is clicked. Stuck on same page.

Earlier it was closing without checking Assigned to & solution.

 

 

Not sure if gsftsubmit must be called.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Naveen87 

you can handle this within UI action code itself and no client script required

check this link and it has solution

Close task UI Action 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Naveen87 

you can handle this within UI action code itself and no client script required

check this link and it has solution

Close task UI Action 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar ,

I tried but no luck.

sc task is still getting closed with any alert or setting fields Mandatory.

function onCloseTask() {
    var assignedTo = g_form.getValue('assigned_to');
    var solution = g_form.getValue('u_solution');
    if (!assignedTo || !solution) {
        alert('Assigned To and Solution fields are mandatory. Please fill them out before closing the task.');
        g_form.setMandatory('assigned_to', true);
        g_form.setMandatory('u_solution', true);
        return false; // Prevent the UI action from executing further
    }
    // If both fields are filled, allow the UI action to proceed
    //return true;
    gsftSubmit(null, g_form.getFormElement(), 'close_catalog_task'); //call action name
}
if (typeof window == 'undefined')
    closeTask();

function closeTask() {
    current.u_closure_code = 'Successful';
    current.state = 3;
    current.update();
    action.setRedirectURL(current);
}

 

Naveen87_0-1711348315914.png

 

@Ankur Bawiskar ,

It worked when i did this.

Naveen87_1-1711348506924.png