How to fetch field values on dialog box from one doctype and submit to another doctype

Hello guys.
I want to fetch field values on the dialog box from Doctype A and submit the values to Doctype B.
below is my custom script and screenshot
// frappe.ui.form.on(‘Equipment’, “create”, function(frm) {
// var subject = frm.doc.subject;
// var event_type = frm.doc.event_type;
// });

frappe.ui.form.on(“Equipment”, “refresh”, function(frm){
// add button fuction
frm.add_custom_button(“Transfer Equipment”, function(click){
var equipment_name_list=[];
var name_list=[];

var equipt=cur_frm.doc.equipment_name;

// function to fetch only from current document
frappe.call({
method: ‘frappe.client.get_list’,
args:
{
‘doctype’: ‘Equipment’,
‘fields’: [‘equipment_name’,‘serial_number’, ‘quantity’, ‘equipment_condition’],
filters:
{
name:frm.doc.name,
}
},
async: false,
callback: function( r)
{
name_list= r.message;
var options = name_list[0];
arr = Array.from(Object.keys(options), k => options[k]);

		}

        });

// Function to show dialog box
var d = new frappe.ui.Dialog({
‘fields’: [
{“fieldtype”: “Data”, “label”: “Equipment Name” , “fieldname”: “equipment_name”},
{“fieldtype”: “Data”, “label”: “Serial Number” , “fieldname”: “serial_number”},
{“fieldtype”: “Int”, “label”: “Quantity” , “fieldname”: “quantity”},
{“fieldtype”: “Select”, “label”: “Equipment Condition” , “fieldname”: “equipment_condition”, “options”:equipment_name_list},

],
primary_action: function(){
    d.hide();
    show_alert(d.get_values());
}

});

d.show();

});
});

1 Like