Change naming field .. not reflection on old fields

i have custom doctype . i choose field XWZ to be my naming field for this doctype
– now i want to change that … i want to use JFC field to do the naming …

it works fine for new records but the old ones not ??

what is the safest way to update old records

The new naming field will only apply for documents created after it is set and onwards. What is the reason for changing the fields? it might not be a good idea as the documents may be linked with other documents.
either data import tool to update (if your custom doctype allows updating that field)
OR a BOLD move… changing the DB directly… but at your own risk.

Its linked with other docs , i can program a code to search in other doc and update them then db update all fields …but I believe there is a smarter more simple way to update naming for all records related to this doctype

When open old records there’s a missed vale for mandatory field i add as naming … when i insert the value and save the field disappear ! And the naming still the old name

if your case is that simple you can do it for the old names by simple python script like:

for d in frappe.db.get_all("Doctype"):
     doc = frappe.get_doc("Doctype", = se.youField

or by import data tool
or if it has a numbering series you can accomplish this by using autoname function

from frappe.model.naming import make_autoname
for d in frappe.db.get_all("Doctype"):
    doc = frappe.get_doc("Doctype", = make_autoname(prefix + '-.##')

hope that helps

1 Like

Ramaddan kareem my friend, this code will handel the old records but will not rename populate the new name in doctypes that use the old name as reference for example item change but in invoice its the old one … since its the pk you lost the reference… in the other hand when i rename normally i change the name every where. This the case i want to cover

Habibi Dude,
Firstly, you have to handle the names in the linked doctypes also by a script, secondly, about to keep change the field that sets the name of your document it MUST be inserted only the first time when the document is local because its a database issue of validation that prevents you to change the name of your PK field,
you can check the Item master Doctype, it only shows the ITEM CODE “which sets the Item table name” field the first time you create it when it is local, and then disappears when you save it and there are many doctypes like so.

:blush: cheers

Scripts scripts :pray: i just wished there is away without scripts :joy::joy: i will give it a shoot tomorrow

1 Like