Dear Community,
I had two doctypes
a.snag
b.department
a.Snag Doctype
Fields as
1.Department (link) as department,option as Department
2.Assigned To (link) as assigned_to , option as User
3.Status(select) as status
b.Department Doctype
Fields
1.Responsible Person (Link) as custom_responsible_person,option as User
In Department i assigned Responsible person for particular department
based on that Department particular person assigned for particular department
Here once we enter department notification send via email and system notification for certain assigned person also once he assigned to user same method need for user then finally notification of status need to received,
I tried custom script but it only show the message sent but no notification received by responsible person.
Code:
Notify the Responsible Person when a Snag is Created
frappe.ui.form.on('Snag', {
after_save: function(frm) {
if (frm.doc.department) {
// Fetch Responsible Person from Department
frappe.call({
method: "frappe.client.get_value",
args: {
doctype: "Department",
fieldname: "custom_responsible_person",
filters: { name: frm.doc.department }
},
callback: function(r) {
if (r.message && r.message.custom_responsible_person) {
let responsible_person = r.message.custom_responsible_person;
// Send email to Responsible Person
frappe.call({
method: "frappe.core.doctype.communication.email.make",
args: {
recipients: responsible_person,
subject: `New Snag Created in Department ${frm.doc.department}`,
content: `A new snag has been reported in the department ${frm.doc.department}. Please review and assign the task.`,
doctype: frm.doc.doctype,
name: frm.doc.name,
send_email: true
}
});
// Show in-system notification
frappe.show_alert({
message: `A new snag has been created for the department ${frm.doc.department}. Please review it.`,
indicator: 'blue'
});
frappe.msgprint(`Notification sent to the Responsible Person for department ${frm.doc.department}.`);
}
}
});
}
}
});
Kindly help to solve this issue