Upper case issue

I have written a client script in which I am saving the item code or item name in upper case or it is running smoothly but the problem is that when I add the item through quick entry, the code is not working.

My code

frappe.ui.form.on('Item', {
refresh: function(frm) {
    // Capitalize item code on form load
    if (frm.doc.item_code) {
        frm.set_value('item_code', frm.doc.item_code.toUpperCase());
    }

    // Capitalize item name on form load
    if (frm.doc.item_name) {
        frm.set_value('item_name', frm.doc.item_name.toUpperCase());
    }
},

validate: function(frm) {
    // Capitalize item code before saving
    if (frm.doc.item_code) {
        frm.doc.item_code = frm.doc.item_code.toUpperCase();
        frm.refresh_field('item_code');
    }

    // Capitalize item name before saving
    if (frm.doc.item_name) {
        frm.doc.item_name = frm.doc.item_name.toUpperCase();
        frm.refresh_field('item_name');
    }
}
});

Thank You.

Client script does not work in the quick-entry. You have to create a server script for that.

DocType Event: Before Insert

if doc.item_code:
    doc.item_code = doc.item_code.upper()

if doc.item_name:
    doc.item_name = doc.item_name.upper()

Then test it. it will work (I tested).

1 Like

Thank You