Hello Team , I am working on some courier integration and I have one condition that before making request to service provider the document should be submitted and then after getting response back the field values should be updated in the same document. To achieve this I am using frappe.db.sql (UPDATE tabDoctype SET fieldname1 = %s , fieldname2 = %s where Doctype.name) , But the value is not updated on database . Also I got the error called " can’t change the docstatus from submit(1) to Draft(0)". If Anyone have solution to solve this error then please reply ASAP .
Hi @adesh can you specify what controller/method you use?
From my perspective, you can follow these steps:
Maybe you can use the controller “before_submit” on your corresponding doctype, then call API or function to fetch some field values from your courier provider.
After you get the values, then you can update it self.fieldname = “some_value”
**note
if the API failed or has some error in it, the document will not be submitted
In addition, if you use controller “after_submit” then you must set the value using frappe.db.sql that you mention before.
If used correctly the value should be updated. Maybe try to reload the Form or verify via mariadb / sql.
If your error is
Also I got the error called " can’t change the docstatus from submit(1) to Draft(0)".
You should recheck your code, make sure the document that you saved not change back it to 0. Or other document as well.