Custom button script

Good Morning Guys
I am a new in Frappe framework and ERP NEXT.
I have a two doctype named Tasks jobs, I want to make a button in jobs doctype to get submitted tasks like in sales order button that get submitted quotations in ERP NEXT, thanks for help and corporate.

Hi @Ahmed_Abdelkarim_Abo,
please use this code for help
//to create custom button
frappe.ui.form.on(ā€œFerro Pipelineā€, {
refresh: function(frm) {
var me = this
if(!frm.doc.islocal) {
cur_frm.add_custom_button(
(ā€˜Make Ferro Orderā€™), function() {
cur_frm.cscript.make_ferro_order();
});
}
}

Thanks for your quick response, but when I write down the script below the button doesnā€™t appear.

the script:-
cur_frm.cscript.make_ferro_order =function(){
frappe.model.open_mapped_doc({
method: ā€œkpi.kpi.doctype.ferro_pipeline.ferro_pipeline.make_ferro_orderā€,
frm: cur_frm
});
}
if (this.frm.doc.docstatus===0) {
cur_frm.add_custom_button(__(ā€˜Tasksā€™),
function() {
frappe.model.map_current_doc({
method: ā€œexternal_maintenance.External Maintenance.doctype.Tasks.Taks.jobsā€,
source_doctype: ā€œTasksā€,
get_query_filters: {
docstatus: 1,
status: [ā€œ!=ā€, ā€œClosedā€],
}
})
}, __(ā€œGet Tasks fromā€));
}

I tried also the script below:

frappe.ui.form.on(ā€œjobsā€, ā€œbutton_3ā€, function(frm) {
frappe.model.with_doc(ā€œTasksā€, frm.doc.status, function() {
var po = frappe.model.get_doc(ā€œTasksā€, frm.doc.status);
frm.set_value(ā€œopen_ticket_dateā€, po.open_ticket_date);
});
});

I got the error as shown

hi,
please use this code
frappe.ui.form.on(ā€œDoctype Nameā€, {
refresh: function(frm) {
var me = this
if(!frm.doc.islocal) {
cur_frm.add_custom_button(
(ā€˜Button_Nameā€™), function() {
cur_frm.cscript.make_ferro_order(); //Method to click on button
});
}
}

frappe.ui.form.on(ā€œtestā€, {
refresh: function(frm) {
var me = this
if(!frm.doc.__islocal) {
cur_frm.add_custom_button(_(ā€˜button1ā€™), function() {
//cur_frm.cscript.make_ferro_order()
cur_frm.add_fetch(ā€œtestā€, ā€œopen_ticket_dateā€, ā€œopen_ticket_dateā€)
});
}
}

I tried this but I found nothing in the screen the button name is button1 and not linked in options, when I remove this code the screen appear again

@Ahmed_Abdelkarim_Abo
refer code from sales_order.js and ā€˜make_sales_orderā€™ method from quotation.py for that
your code will be like that -

//condition to add custom button
cur_frm.add_custom_button(__('From Tasks'),
			function() {
				frappe.model.map_current_doc({
					method: // path of your py method, 
					source_doctype: "Tasks",
					get_query_filters: {
						docstatus: 1,
						// add your filters 
					}
				})
			});
2 Likes

@sagar
U used var me = this and did not use it at all in the code, why u need it?
Regards
Bilal