Auto Name - can we have customized auto name?

HI Team,

Hope everybody is doing great!

I have created a new doctype for my requirement.

I have tried all Auto Name options available.

I want to have Auto Name in the following manner,


Is it possible?

Everything comes perfect but instead of fetching field name, file gets name as Prefix/ABC/field:[fieldname]/01

1 Like

It should be field:fieldname try removing the brackets .

1 Like

Thanks for prompt response Muthu,

I tried it as well, but it does not resolve my concern.

Say for example I want to have Item name in between some prefix and some serials.

It comes with document name as Prefix/ABC/field:item/.01

Please explain in detail , how you want that to be and if possible I would help you .

Thanks for extending support hands.

I have created a new DocType.

System built Auto Name works perfect, but I want some modifications in it.

I want a document name in the following manner:


Where Item and numbers should be changed according to item.

Say item P has first version, so document name should come


If it is for item Q it should come like


When there is a second version of item P it must come up with name Prefix/ABC/P/02 even it is created after Prefix/ABC/Q/01. Rather than creating Prefix/ABC/P/03

But very first concern, field:[fieldname] is not being fetched if it is within some alpha / numbers

Understood but what about the Prefix/ABC is all about ? Is that fixed or will that change ??

For now it is fixed, if we can get multiple fields in document name using inbuilt Auto Name feature, should we add more than one fields like naming series (for Prefix/ABC like phrase), item name etc.

Ultimately document must be generated item wise in version manner.

I want it the way how Salary Slip names are generated.

@brillarescience Use this code to achieve the desired result , I hope you are setting the item name in item_name field and the value in item_code field , then set the auto name as field:item_code in your doctype

cur_frm.cscript.custom_item_name = compute;
function compute(doc, cdt, cdn)
//To check the first digit of the code
temp_code = "";
temp_code = doc.item_name.charAt(0);
//Get a list of all the codes with the same first digit{ method:"frappe.client.get_list",
doctype: "your_doc_name",
filters: {"item_code": ["like", temp_code + "%"]},
fields: ["name"],
limit_page_length: 500
callback: function(r) {
//Count the number of elements in the list (which will decide what code to try)
if (r.message) {
temp_code += zeroPad(r.message.length, 5);
console.log(temp_code );
temp_code += "0000";
console.log(temp_code );

doc.item_code= temp_code;
function zeroPad(num, places) {
var zero = places - num.toString().length + 1;
return Array(+(zero > 0 && zero)).join("0") + num;

Thanks once again,

How to use the sent code?

Should I create a custom script for created DocType?

1 Like

Yes, that is correct,