Autoname Custom Doctype

Hello,

Is there a way to have the autoname generated from 2 different fields?

Thanks!

Can you please explain your issue and business case.

I have created a custom Doctype.
What I need is to have the name of each document that is created in that DOCTYPE generated automatically based on the fileds that I want so example:

From this 2 fields to have the name generated.

now the name of the document is set on ,Prompt" and iss added manualy. but is timeconsuming.

Not out of the box, You will need to add the autoname method in your custom_doctype.py file

Can you please help me with this?

Assuming you don’t want to add server side scripts:

I would create a custom field in the document that is hidden. Add a custom script that sets the value of that field to what you want (adding the two fields together) in the before_save event. Finally, use the field:[fieldname] option with your hidden field, so that ERP names it correctly.

If you can add server side Python scripts, implement the def autoname(self) in your DocType’s py.

I have added as the Default the fields that needs to generate the name, but still not working.

I am a bit lost…I don’t know how to do this.

You are half way there. Remove the fieldnames from Default on that document.

Create a custom script for that document and include the following code:

frappe.ui.form.on('{REPLACE WITH DOCTYPE}', {
	validate: function(frm) {
		frm.set_value('nume', frm.doc.adrese + frm.doc.descriere);
	}
});

Hopefully that should work.

1 Like

Which type of field should I select?

Now I have the floowing erorr :

But the fileds are completed.

Try this:

frappe.ui.form.on('Sesizari', {
	validate: function(frm) {
		frm.set_value('nume', frm.doc.adrese + frm.doc.descriere);
		frm.refresh_field('nume');
	},
    adrese: function(frm) {
		frm.set_value('nume', frm.doc.adrese + frm.doc.descriere);
		frm.refresh_field('nume');
	},
    descriere: function(frm) {
		frm.set_value('nume', frm.doc.adrese + frm.doc.descriere);
		frm.refresh_field('nume');
	},
});
1 Like

It’s better.

But it still doesn;t pick the second part ( 2nd field ,descriere’')

Any ideea? It’s saying undefined.

If the field is showing undefined, it’s probably because the field isn’t populated. I can’t see where that field is set in your screenshot. Is this the right field name and spelling?

1 Like

You are correct! I was testing in the wrong enviorment where I didnd;t had the correct fileds.

It’s solved!!
Many thanks!