Try ERPNext Buy Support Partners Foundation

When user select uom then which event is trigger

Hello Team,
In my case when user click and edit the uom my function will be call but i want when user select the uom then my function is call so for that i write one custom script can anyone help me for the same.

this is my custom script

frappe.ui.form.on(‘Sales Order’, {

frm.set_query("uom", "items", function() {
    frappe.db.get_value('UOM Conversion Detail', { uom: "Nos" }, "*", '', "Item").then(r => {
        // console.log("Nos",r)
        frm.doc.box_to_nos = frm.selected_doc.conversion_factor / r.message.conversion_factor * frm.selected_doc.qty
        console.log("frm.doc.box_to_nos",frm.doc.box_to_nos)
        console.log("frm.selected_doc.conversion_factor",frm.selected_doc.conversion_factor)
        console.log("r.conversion_factor",r.message.conversion_factor)
})
})

});

i want only this function call when user select the uom then this function is call

You should do this:

frappe.ui.form.on("CHILD_TABLE_NAME", {
	CHILD_TABLE_UOM_FIELDNAME: function(frm, cdt, cdn) {
		// Code here
	},
})

For example, for the Sales Order Item childtable it should be:

frappe.ui.form.on("Sales Order Item", {
	uom: function(frm, cdt, cdn) {
		// Code here
	},
})
1 Like

yes same script i try but it is not working

frappe.ui.form.on(‘Sales Order Item’, {
uom:function(frm,cdt,cdn) {
frm.set_query(“uom”, “item”, function() {
frappe.db.get_value(‘UOM Conversion Detail’, { uom: “Nos” }, “*”, ‘’, “Item”).then(r => {
console.log(“Nos”,r)
debugger
frm.selected.doc.box_to_nos = frm.selected_doc.conversion_factor / r.message.conversion_factor * frm.selected_doc.qty
frm.refresh_fields(cur_frm.selected_doc.box_to_nos)

})
})

}

});

not working even debugger also not working

error

form.min.js?ver=1580476664.0:1 Uncaught (in promise) TypeError: Cannot read property ‘grid’ of undefined

Are you sure about the set_query part? Try without it. Or maybe i’m not understanding what you want to do. Try this:

frappe.ui.form.on(‘Sales Order Item’, {
     uom: function(frm,cdt,cdn) {

          frappe.db.get_value(‘UOM Conversion Detail’, { uom: “Nos” }, “*”, ‘’, “Item”).then(r => {
                   console.log(“Nos”,r)
                   frm.selected.doc.box_to_nos = frm.selected_doc.conversion_factor / r.message.conversion_factor * frm.selected_doc.qty
                  frm.refresh_fields(cur_frm.selected_doc.box_to_nos)

         })
    }
});
1 Like

i want if user select uom = box then my function is execute calculated value automatically display in the custom filed that i have created name is box_to_nos

that set

Then it’s a little bit more complex, you should use something like this to set value:

var selected_row = frm.get_field("items").grid.grid_rows_by_docname[cdn];
var calculated_value = selected_row.doc.conversion_factor / r.message.conversion_factor * selected_row.doc.qty
selected_row.get_field("box_to_nos").set_value(calculated_value)

can u please help me for the same using above script calculation part is done but whenever i select the uom box then an then this function will call this part is remaining can u please help me for the same

I’m not confortable giving you the complet code, so, this is my last comment, this should do all of what you want, if not, try to correct it by yourself:

frappe.ui.form.on('Sales Order Item', {
     uom: function(frm,cdt,cdn) {
     	  var selected_row = frm.get_field("items").grid.grid_rows_by_docname[cdn];

     	  if(selected_row.doc.uom != "box"){
     	  	return
     	  }
          frappe.db.get_value('UOM Conversion Detail', { uom: 'Nos' }, '*', '', 'Item').then(r => {
			var calculated_value = selected_row.doc.conversion_factor / r.message.conversion_factor * selected_row.doc.qty
			selected_row.get_field("box_to_nos").set_value(calculated_value)
         })
    }
});
1 Like