Client Script for Custom Naming Series

Hi,

Im trying to create a custom naming series for the items, however it seems that the client script doesnt work.

Here is the code Im trying. Can anybody help me?

frappe.ui.form.on("Item", 
{validate: function(doc) {
    // clear item_code (name is from item_code)
    doc.item_code = "test-";

    // first 2 characters based on item_group
    switch(doc.item_group) {
        case "Ceramic Capacitors":
            doc.item_code += "101-";
            break;
        case "Electrolytic Capacitors":
            doc.item_code += "TB-";
            break;
        default:
            doc.item_code = "XX";
    }
    
    doc.item_code +="test";
    
}
});

frappe.model.set_value is a good fit for that kind of operations.