Problem with Client Script to Select Naming Series

Hello,

I have created several options in the naming_series of the Item DocType, which I want to select depending on the item_group selected. However, it doesn’t seem to work.

Can anyone help and tell me where I’m going wrong?

Thanks

    refresh: function(frm) {
        frm.fields_dict['Item Group'].on("change", function() {
            var item_group = frm.doc.item_group;

            if (item_group === "Other") {
                frm.set_value("Naming Series", "GIN-.#####.");
            } else if (item_group === "CAT-1 Raw Materials" || item_group === "CAT-2 Consumables") {
                frm.set_value('Naming Series', ".{custom_pn_class}.-.{custom_pn_value_1}.-.{custom_pn_value_2}.-.###.");
            } else if (item_group === "CAT-3 Sub-Assemblies" || item_group === "CAT-4 Semi-Finished Goods") {
                frm.set_value('Naming Series', ".{custom_pn_product_line}.-.{custom_pn_class}.-.{custom_pn_value_1}.###.");
            } else if (item_group === "CAT-5 Finished Products") {
                frm.set_value('Naming Series', ".{custom_pn_product_line}.-.{custom_pn_class}.-.{custom_pn_value_1}.-.{custom_pn_region_code}.-.{custom_pn_language_code}.-####.");
            }
        });
    }
});

@pmjd first you have to edit the doctype and add all the options to the naming_series select field. second try this code:

frappe.ui.form.on('Item', {
	item_group: function(frm) {
		var item_group = frm.doc.item_group;
		if (item_group=="Other"){
		    frm.set_value("naming_series","GIN-.#####.")
		}
	}
})

Thanks for looking, I have already edited the DocType to add all the options I needed.

I have tried your code, with just the single option, and with the item group set to “Other” it does not change the naming series to GIN-######

Do you have any other suggestions?

@pmjd I did tried the code and it works fine . can you share screenshots ?

scrnli_9_13_2023_4-32-01 PM

Hi @pmjd,

@bahaou code is perfectly suitable according to your scenario.

Please try again and check it.

Thank You!

So sorry, a typo on my part in the naming series, thank you @bahaou your code is working perfectly :sunglasses: