PHP - frappe.exceptions.DocstatusTransitionError: Cannot change docstatus from 0 to 2

Hi.

I’m trying to update a Patient Encounter using PHP, but I get this weird error:

 frappe.exceptions.DocstatusTransitionError: Cannot change docstatus from 0 to 2
$ch = curl_init($baseurl . 'api/resource/Patient%20Encounter');

            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

            curl_setopt($ch, CURLOPT_POST, true);

            curl_setopt($ch, CURLOPT_POSTFIELDS, '{

            "docstatus":"1", "patient":"' . $_POST["patient"] .",
            ...rest of post data...}');

Now if I remove the "docstatus":"1"-part the data gets inserted but only as a draft. The only thing that’s not working is the “docstatus”-part. The docstatus = 1 part submits the document, and that is what I need.

Any ideas why it is like that?

Thank you.

This one took me a minute to catch! :slight_smile:

The immediate problem is that you’re using a string for docstatus, but you should be using an integer. Change your post fields to "docstatus": 1 and it should work.

The larger problem is that the exception messages are misleading. The docstatus transition method in document.py isn’t properly checking for invalid docstatus, so when it gets an invalid doc status it just assumes that you’re trying to make an illegal transition (hence the misleading message).

I’ve made a pull request in hopes that others will have an easier time of it.
https://github.com/frappe/frappe/pull/15194

1 Like

Hi peterg. Thanks alot for taking your time. That solved it. I feel so stupid that I didn’t think of this, haha.

1 Like