Naming series custom

I want to make a condition in naming series driver. if i select type field “driver” naming series field will be “DRV.-” , if i select “kernet” naming series will be “KRN.-”. I already try code below but the naming series only appear on the list not appear on the “type” field. anyone could help? thanks a lot !

frappe.ui.form.on(‘Driver’, {
refresh: function(frm) {
frm.fields_dict[‘type’].$input.on(‘change’, function() {
if (frm.doc.type === ‘Driver’) {
frm.set_value(‘naming_series’, ‘DRV-’);
} else if (frm.doc.type === ‘Kernet’) {
frm.set_value(‘naming_series’, ‘KRN-’);
}
});
}
});

Hi @AmateurDeveloper

Read this post. I hope you find a solution

Thank You!

but I already set it before with type select, do i need to change it?

@AmateurDeveloper You have to change the Type in naming_series

Hi @AmateurDeveloper,

Please check the reference:

frappe.ui.form.on('Driver', {
    type: function(frm) {
        if (frm.doc.type == 'Driver') {
            frm.set_value('naming_series', 'DRV-');
        } else if (frm.doc.type == 'Kernet') {
            frm.set_value('naming_series', 'KRN-');
        }
    }
});

Thank You!

i tried this but in the “type” field not showing the naming series suggestion, but if i save it, it shown at the driver list. do i need to change the type from select to data?

If the field type is “select”, the naming series will automatically be set according to the selected field. However, if the field type is “data”, I have not tried this scenario yet.

Thank You!

But it only automatically aplied in the driver list, when i make new driver and select the type, the naming series doesnt auto apply based on the rules

Please again check your client script.

Another reference:

i’ve tried this one, and finally it works. thankyou so much !