Good day
adding client script fro a barcode to Purchase Order.
I have added a field called “PO Barcode” to my form
and added the script below. to populate the POBarcode field with the PO-nr.
frappe.ui.form.on('Purchase Order', {
after_save: function(frm) {
frm.set_value('po_barcode', frm.doc.name);
}
});
I used the after_save trigger because the new PO-nr is only generated after I SAVE.
But now, after I save, the field is updated, putting the form back into UNSAVED state.
And so it just carries on. And I can’t use BEFORE SAVE because the POnr is not generaated then yet.
Then I added a custom button that the user can click. And if you click it after save, it
does indeed populate the barcode field with the PO nr BUT if the user clicks the button
BEFORE the PO nr is assigned it will load the New-Purchase Order -01
This is my button code …
frappe.ui.form.on('Purchase Order', {
refresh: function(frm) {
// Fetch sales order number from the work order doctype
frm.add_custom_button(('Get Barcode'), function(){
frm.set_value('po_barcode', frm.doc.name);
},("Barcode"));
}
});
Can someone please assist me to get iether method working , I am stuck … thanks