How to naming a doc based on a hidden field

I’m trying to autoname my doc based on a hidden field that contains full_name
that field will be filled before save and it gives me Full Name is Required…

any idea thanks in advance

if your field have always value before saving then you can apply naming rule.

thanks for the replay, but my field gets its value when before_save trigger

You can try this:

on server side:

def on_update(self):
       if self.full_name:
             self.rename(self.full_name)
             frappe.response.new_doc_name = self.full_name

and on client side:

after_save(frm) {
		const { new_doc_name } = frappe.last_response;

		if (new_doc_name && frm.doc.name !== new_doc_name) {
			$(document).trigger("rename", ["YOUR_DOCTYPE",  frm.doc.name, new_doc_name]);

			if (locals["YOUR_DOCTYPE"] && locals["YOUR_DOCTYPE"][old_doc_name]) {
				delete locals["YOUR_DOCTYPE"][old_doc_name];
			}

			frm.refresh();
		}

}

I appreciate your help, but this snap doesn’t help (on_update: gets called when values of an existing document are updated), it results in an error message that the document is not allowed to rename. I replaced it with after_insert and it works just after submitting the form but when I return to display the document it returns to show the ID again as the doc title, I just want the title of the doc to be the full name

@Gharieb Please change the full_name field value is update with your first_name, middle_name or last_name field if it is available so please write field value change logic and then try it

Example of code For Customer Doctype:

def autoname(self):
     self.name = self.first_name + self.middle_name + self.last_name


try this @Gharieb

1 Like

thanks a lot that’s awesome it works