Little Help with Msgprint Scrip!

Hello, i am trying to create a script that evaluate two fields inside the sales invoice item table, when the nqty field changes the scrip should evaluate in this case the qty and actual_qty and if condition is valid print a message. Any idea how the syntax should be? this is what i was trying :

  frappe.ui.form.on("Sales Invoice Item", "nqty", function(frm) {
        if (frm.doc.qty > frm.doc.actual_qty()) {
            msgprint(__("No enough inventory on Hand"));
        }
    });

frm.doc.actual_qty is field so just use frm.doc.actual_qty instead of frm.doc.actual_qty()

2 Likes

Thanks but by changing that still dosent work, the condition must be meet at doctype child table level, when i change the value of the qty field, when a user insert a new record where the qty of inventory is less thant the amount in order it should print the alert.

@Randy_Lowery,

Try

frappe.ui.form.on("Sales Invoice Item", "nqty", function(frmm cdt, cdn) {
	doc = locals[cdt][cdn]
    if (doc.qty > doc.actual_qty()) {
        msgprint(__("No enough inventory on Hand"));
    }
});
1 Like

got it, thanks for your advise @makarand_b

Hi again, any advise how to print the doc.actual_qty inside the message

for example: No enough inventory on Hand only 5 in stock.

Found it, ill posted for any one who also needs this :

frappe.ui.form.on("Sales Invoice Item", "nqty", function(frm, cdt, cdn) {
	doc = locals[cdt][cdn]
    if (doc.qty>=doc.actual_qty) {
        msgprint(__("Revisa el Inventario solo {0} disponibles", [doc.actual_qty]));
    }
});