Issue in Data update in doctype

In frappe doctype, data will not be updated with the use of this code

city_doc = frappe.get_doc(“city”, cityname)
city_doc.city = new_city_name
city_doc.save(ignore_permissions=True)

Thanks

Hi @Priyank_Suthar,

code you’ve provided seems generally correct.

Please check the documentation of Document API

I hope this helps.

Thank You!

Hi @NCP,
There is no solution to this problem in that link, according to what I checked

Thanks

Hi @Priyank_Suthar,

Please review the documentation once more.

If the city is an identifier, you cannot modify or update the city_doc.city.
Also, double-check the document type name (whether it’s in uppercase or lowercase) and the field name.

If you update via the bench console then you should add one more line.

frappe.db.commit()

Thank You!

Hi @NCP,

I have checked all parameters from my side and all are correct.

Thanks

Please share the json-file of your city-doctype so we can see what you have defined. Which version of frappe framework are you using?

Hi @thkr_ituc,

Although I did not find any json-file, I have shared a Image to give you a better understanding of the doc-type.

Thanks

@NCP

any update?

Thanks

Hello @Priyank_Suthar,

Please show us a picture of the entire form with all its fields so we can better understand it. The information you provided, like the print preview of the form, is not very clear for us.

Hi @NCP ,

Kindly check images


Thanks

Hmm :thinking:,

The city is like a unique identification, so you can’t change it using your code.
If you need to modify this identification, look at the example below.
Remember, the example is Static, so adjust it based on your own scenario.

old_city_name = "Old City"
new_city_name = "New City"

city_doc = frappe.get_doc("City", old_city_name)

rename_data = {
    "doctype": "City",
    "old_name": old_city_name,
    "new_name": new_city_name
}

frappe.rename_doc(rename_data, ignore_permissions=True)

updated_city_doc = frappe.get_doc("City", new_city_name)

Reference of frappe.rename_doc:

https://github.com/search?q=repo%3Afrappe%2Ferpnext+frappe.rename_doc&type=code

Another reference:

I hope this helps.

Thank You!

hi @NCP,

Thanks For your Support, issue was resolved.