Try ERPNext Buy Support Partners Foundation

Automate ToDo creation for Support Issues

Hi all, I am fairly new to ERPNext. We are currently testing out ERPNext in the hopes that it will be a good replacement for our current ERP. So far we have been thoroughly impressed, however I have been having a bit of trouble with the client-side scripting.

We are a service oriented business, and I have been trying to script the auto-creation of ToDo’s from Issues based on a custom employee linked field. Below is my script so far:

    current_technician(frm) {
    	if(frm.get_docinfo().assignments.toString())
        {

            cur_frm.assign_to.remove(frm.get_docinfo().assignments[0].owner)
            try {
                current = frappe.db.sql("select name from tabToDo where status= Cancelled")
                //frappe.db.delete('ToDo', current[0][0])
                frappe.msgprint('success')
            }
            catch (exception) {
                frappe.msgprint("FAILED")
            }

        }

        frappe.db.insert({
            doctype: 'ToDo', 
            description: cur_frm.doc.subject, 
            owner: cur_frm.doc.current_technician.user_id,
            reference_type: 'Issue',
            reference_name: cur_frm.doc.name
        })
        //cur_frm.assign_to.add();
        //cur_frm.assign_to.dialog.set_values({
            //assign_to:frm.doc.current_technician.user_id,
            //description:frm.doc.subject
        //});
        //cur_frm.assign_to.dialog.hide();
    }

I have been able to succeed at create the ToDo documents, but have not been able to delete old ones(we are wanting to have the ability to escalate and de-escalate the issue and keep the most recent ToDo for all related technicians). Any help would be greatly appreciated :grin:

1 Like