I want to change the ID based on the customer code

I want to change the ID based on the customer code. If the customer code changes, then the document name should also change."

Reference: Naming


I want to use only the code, but the prefix also appears at the end of the code. how can solve this

Use it like

One generated the ID, and the custom_customer_code was updated; however, the ID will not update, which requires server-side logic.

which script to use set customer code as id

Reference:

if doc.custom_customer_code:
    new_id = doc.custom_customer_code.strip().replace(" ", "-").lower()
    if doc.name != new_id:
        frappe.rename_doc(doc.doctype, doc.name, new_id, force=True)
        doc.name = new_id

Note: Be cautious with rename operations, especially if there are linked documents, as it may impact data consistency. Always test thoroughly in a development environment before applying to production.

Renaming in general is a bad idea in Frappeverse.

1 Like

Better use “Document Naming Rule” doctype to setup naming