How to know the Task ID of a task when it is deleted from 'Project'

Hello Everyone,

I need to know the task id of the task, when it is deleted from the project.
How to get it from the client side script.

My code is below. But alert(doc); shows ‘Undefined’ … Anyone why?

frappe.ui.form.on(“Project Task”, “tasks_remove”, function(frm, cdt, cdn) {
var doc = frappe.get_doc(cdt, cdn);
if(doctask_id != null) {
frappe.db.sql(“delete from tabProject Task where task_id = %s”, doc.task_id)
} else {
msgprint(__(“not deleted.”));

Refer following syntax -

frappe.ui.form.on("Project Task", "field_name", function(frm,cdt, cdn) {
     var d = locals[cdt][cdn];
     alert(d.task_id)        //print task id of respective task
     //your code

Regards, Priya

1 Like


Actually I want the task_id of the deleted row!

Your code above is fine and will get the task_id. But I need the task_id when that row is deleted.

that is,
frappe.ui.form.on(“Project Task”, “tasks_remove”, function(frm,cdt, cdn) {
var d = locals[cdt][cdn];
alert(d) //print d as "undefined’

@Amalendu, When you remove task from Project Tasks child table, parentfield not found for removed record, so task id shows undefined. So, Why do you want removed row task id?
Also after removed task and save this project then this task automatically get deleted from Task list except if you not created time log against that task.


Because, the last task can never be deleted from Project in ERPNext. It is saved again!
My idea is to delete task from the table ‘Task’ directly.

OR is there other way to delete task from the ‘Project’ itself. It is required now urgently.