Hello,
I want automatic generation of Item Code based on Item Name and Packing in gms.
For example ;
Item Name: Amul Gheee
Packing in gms : 500gm
Item code should made as AG500.
How can I achieve this ??
Hello,
I want automatic generation of Item Code based on Item Name and Packing in gms.
For example ;
Item Name: Amul Gheee
Packing in gms : 500gm
Item code should made as AG500.
How can I achieve this ??
Client Script;
frappe.ui.form.on('Item', {
item_name(frm) {
generate_item_code(frm);
},
packing_in_gms(frm) {
generate_item_code(frm);
}
});
function generate_item_code(frm) {
let name_initials = frm.doc.item_name.match(/\b(\w)/g).join('');
let packing = frm.doc.packing_in_gms.match(/\d+/g)[0];
let item_code = `${name_initials}${packing}`;
frm.set_value('item_code', item_code.toUpperCase());
}
Not tested.
@Yamen_Zakhour Can I implement this script in ERPnext client script directly or I have to use this in backend files.
If you have developed a custom app, you can place the app in the custom app. Otherwise, you can place the script in the client script doctype.
Thank You!
Hi @pm23
Please try this code and you can directly apply this script in ERPNext client script.
frappe.ui.form.on('Item', {
item_name: function(frm) {
generate_item_code(frm);
},
packing_in_gms: function(frm) {
generate_item_code(frm);
}
});
function generate_item_code(frm) {
if (frm.doc.item_name && frm.doc.packing_in_gms) {
let name_initials = frm.doc.item_name.match(/\b(\w)/g).join('').toUpperCase();
let packing = parseInt(frm.doc.packing_in_gms);
if (!isNaN(packing)) {
let item_code = `${name_initials}${packing}`;
frm.set_value('item_code', item_code);
} else {
frm.set_value('item_code', '');
frappe.msgprint('Invalid packing value. Please enter a valid number.');
}
}
}
Thank You!
Ok Will try and check.
Thanks!!