Changing docstatus directly in code without using Submit button/Is Submittable

Hi Team, All,

I have a DocType that has a status field with values “Draft”, “In Process”, “Finished”.

I would like to make documents with this DocType uneditable when they are in the “In Process” or “Finished” states. My use-case does not really support the “Is Submittable” concept and these states can be entered by pressing a custom button more suited to what I’m trying to do.

Is it okay to set document.docstatus = 1 programmatically in my controller (or in the client JavaScript) when the button is clicked?


You can do this, but you’d probably be better off writing a client side script where you add buttons to the form for “In Process” and “Finished”, then make the fields themselves read only. Here is a sample of how to make a field read only when saving:

cur_frm.cscript.custom_refresh = function(doc) {
// use the __islocal value of doc, to check if the doc is saved or not
cur_frm.set_df_property(“myfield”, “read_only”, doc.__islocal ? 0 : 1);

from: Client side scripting · frappe/frappe Wiki · GitHub

Thanks Ben,

I considered this but didn’t want to have to set the readonly field-by-field (especially if I have to update the code every time I add a new field) as it seemed quicker to just do it with the docstatus.

I have created the custom buttons in my client script.