Item Code auto generation

In Item Group Tree make a new custom field like the one on the right. Set FG, SCG etc. for each

In naming series Item use the code as below. There’s a dot between abbr and ###. Keep the dot and add number of ####. If 4 # then your item code will have max four digits. Use your field name.

item_group_abbr.#########

System generated item code using naming series.
image

3 Likes

for this use case, you can use Document Naming Rule where you can Define the Item Type Wise Naming.

1 Like

Thank you so much Muzzy,let me give it a try and get back to you.

Thank you Ranbir, if you can please show me an example with a screenshot.

Sure, here is a Example with Screenshot.
Use case - If Item Group = Raw Material, then New Item Code Generate as RM-0001.
you can also manage the Document counter in future if you want to reset.

1 Like

Thank you, I did try and was able to create multiple naming rules for each options in the group, but they are not appearing in the item code field when I create a new Item. please help me

  1. Stock Settings >>Item Naming By (Naming Series)
  2. setup Document Naming Rule for each Item Group
1 Like

Thank you so much santhida, it works like a charm

1 Like

FYI. It will work only once 1st time at item creation. If you edit the group on item master it will not change. So set it carefully and correctly.

1 Like

Thank you Muzzy

Hello All Experts,

I am looking to auto generate the description of Item.
For example, I have below :slight_smile:

2 check boxes -
Gate - Check box
Globe - Check Box

1 Select Field -
Material - (SS, MS, CS, etc in list)

1 Select Field -
Ends - (flange, threaded, etc in list)

Now based on above selection - I want Description Field to auto generate - Like if i check “Gate” and select “SS” and “flange” then the description shall display “Gate, SS, Flange”

Workout Something like this, your valuable inputs will be helpful.

Client or Server Script

I tried various scripts but unable to do so. In fact the earlier deleted script is running but the current one is not showing up or working. Can you please guide.

It looks almost like the thing I want to do. However I have a few Items Groups that I want to combine into the same number range. I created a custom field at the item group, with a selection.
In the Document Naming Rule, I would like to use that new custom field for the Rule Condition, however I cannot select that field from the list. Is there a way to use that field in the Rule Conditions? Or can I only use the Item Group field?
And is it possible to leave the Prefix field empty? I would just prefer to have a different number range for different groups. Like

Group A - Number 1000 - 4999
Group B - Number 5000 - 8999
Group C - Number 9000 - 9999

I have a custom script deleted (created on item doctype) but it still works on item form. And I tried on other browser, it still works, and i reset chrome but it still works. I have a self hosted on virtual box. In fa t the other vms also give same script but it is not in script list.

No need to any script and all programming skill…
Create item group what you want and then go to document naming rule and follow my this post.

This post considering journal entry doctype.

  1. you can select “item” in document type field
  2. make it rule condition field in item_group = <Your_item_group_list> like Finished Goods
  3. set prefix what you want like FG.-.
  4. Finally, set digit like 5

so once you create item then generate code like FG-00001

Thanks. I tried that, but somehow it doesn’t work as hoped.

  1. Selected Item in document type
  2. Made two rules: is_sales_item = Yes + item_group = Events
  3. Set a prefix EVT
  4. Set digit.

Now when I create a new item, define the name, item group Events and mark it as a sales item and save, it creates an item code: STO-ITEM-2023-00001.

I selected Naming Series under Item Naming By in Stock Settings. Where else do I have to define that?

One other question:

How can I omit the Prefix set in 3? I just want a number, not a CHAR0000 format

For Reference Document naming series & Document naming rules is responsible to design or generate user specific code check twos DocType.

Your Problem @matthkarl
2. Made two rules: is_sales_item = Yes + item_group = Events

Instead of
is_sales_item = 1
item_group = Events

Make sure item group name same in item group list.
System will check case-sensitive manner wile triggering this.

Hope you understand…!

Thanks. Changing the rule to 1 instead of yes did the trick.
But I guess the naming rule still needs a Prefix, as I can’t save the rule without one.

Done with the below code where gate and globe are custom check boxes. Description-1 and description -2 are custom read only fields.
Gate sub type is custom select field and description is default item description field.

If someone has a better way to put this, let me have your valuable suggestions.

frappe.ui.form.on(‘Item’ , {
validate:function(frm){
frm.set_value(‘description_1’, frm.doc.gate_sub_type + " " + frm.doc.body);

    }

});

frappe.ui.form.on(“Item”,“gate”, function(frm){
if(cur_frm.doc.gate == “1”){
cur_frm.doc.description_2 = “Gate Valve”;
cur_frm.refresh_field(‘description_2’);
} else {
if(cur_frm.doc.gate == “0”){
cur_frm.doc.description_2 = " ";
cur_frm.refresh_field(‘description_2’);
}
}
});

frappe.ui.form.on(“Item”,“globe”, function(frm){
if(cur_frm.doc.globe == “1”){
cur_frm.doc.description_2 = “Globe Valve”;
cur_frm.refresh_field(‘description_2’);
} else {
if(cur_frm.doc.globe == “0”){
cur_frm.doc.description_2 = " ";
cur_frm.refresh_field(‘description_2’);
}
}
});

frappe.ui.form.on(‘Item’ , {
validate:function(frm){
frm.set_value(‘description’, frm.doc.gate_sub_type + " " + frm.doc.body + " " + frm.doc.description_2 );

    }

});