If i make an Opportunity and the opportunity is lost, i want to get the lost_reason, opportunity_name, party_name, opportunity_from, sales_person data to the lead lost history table. is anyone can help? thanks a lot
You have to develop the client/server script for that.
can you help me revised the code? i already made the client/server script but seems nothing happen. below i give my code
js:
frappe.ui.form.on(‘Opportunity’, {
refresh: function(frm) {
// Custom refresh logic if needed
},
status: function(frm) {
if (frm.doc.status === ‘Lost’) {
frappe.call({
method: ‘my_doctype.my_doctype.overrides.opportunity.add_to_lead_lost_history’,
args: {
opportunity_name: frm.doc.name,
lead: frm.doc.lead,
lost_reason: frm.doc.lost_reason,
posting_date: frm.doc.posting_date,
sales_person: frm.doc.sales_person
},
callback: function(r) {
if (r.message === ‘success’) {
frappe.msgprint(__(‘Opportunity status changed to Lost and updated in Lead Lost History’));
}
}
});
}
}
});
python:
import frappe
from frappe.model.document import Document
@frappe.whitelist()
def add_to_lead_lost_history(name, opportunity_name, lead, lost_reason, posting_date, sales_person):
try:
lead_doc = frappe.get_doc(‘Lead’, lead)
lead_doc.append(‘lead_lost_history’, {
‘ref’: name,
‘lost_reason’: lost_reason,
‘date’: posting_date,
‘doctype_name’: opportunity_name,
‘sales’: sales_person
})
lead_doc.save(ignore_permissions=True)
return ‘success’
except Exception as e:
frappe.log_error(message=str(e), title=“Error in adding to Lead Lost History”)
return ‘error’
No, the code worked from the opportunity.js file so please check the code when you click on status lost.
this one?
status:function(frm){
if (frm.doc.status == “Lost”){
frm.trigger(‘set_as_lost_dialog’);
}
},
yes … !
so, what should i do next?
You have to read and learn the code and one by one apply it yourself according to the scenario.
can u help me with that? i am really confused
i need when the opportunity is lost then i need the lost_reason, opportunity_name, party_name, opportunity_from, sales_person data to the lead lost history table on doctype lead
