Update the field value when docstatus is submit(1)

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 .

Thanks !!

Hi @adesh can you specify what controller/method you use?

From my perspective, you can follow these steps:

  1. 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.
  2. 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

Here is the documentation about the controllers
https://frappeframework.com/docs/user/en/basics/doctypes/controllers

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.

@antzforwork Thank you for response … I am not using any controller method !!

then can you share your snippet code? maybe we can help it from there…

@antzforwork After reloading the form the values is disappear and not update in database.

after this statement frappe.db.sql (UPDATE tabDoctype SET fieldname1 = %s , fieldname2 = %s where Doctype.name)

use >> frappe.db.commit() this is will aow to change submited document values,
if you have any query feel free to ask me
Thanks !