How to Close Unapproved Workflow States

Hi guys

I have set a workflow which in many cases would go to unapproved(rejected) status, unapproved status is actually the workflow_state of the document which it means that doc status remains “Draft” but is the end of the process since it is rejected by the user.

Since we have only 3 status for the doc, i.e. “Approved” , “Cancelled” and “Drfat” I actually didn’t have any other option to set the docs status. On the other hand you know that draft documents, e.g. draft stock transactions are displayed as pending(gray) in different forms of system(for example draft stock transactions are grayed out in work order form > connection section)

Now my question is how I can handle these draft docs which are in fact unapproved considering following needs:

  1. I don’t want these docs to be displayed somehow as open docs(now they are in gray in different forms)

  2. I don’t want to delete these docs since the numbering would b gapped this way and also the history would be lost

Regards,
Mary

1 Like

I’m not completely understanding your question, and I wonder if you’re thinking about docstatus incorrectly. For starters, not all documents use docstatus. For many doctypes, especially “Masters” that don’t go through a submission process, the docstatus is always 0.

Submittable documents, on the other hand, have three different possible values: 0 (Draft), 1 (Submitted), or 2 (Cancelled). It is only possible for a document to move up, from 0->1 or from 1->2.

In your workflow, you have the option to align each workflow state to a docstatus. If you want unapproved things to be cancelled, just put “2” in the docstatus field when defining the state.

1 Like

Sorry to jump in even we have to face the same situation there are a few documents as per workflow status it states canceled but in actuality it was cancelled so whenever we inactive the workflow we placed system will show their current status and since it’s in the draft you cannot cancel this document as for that you have to first submit the document first.

Thank you for the response

I understand what you say but as you know it is not possible to cancel a document before it is approved, it means that if I want to take rejected documents to cancelled status (by setting : Workflow > Status > Rejected status. Doc Status=2)

first it must be approved !!!

Even if I do such setting, system shows Error: Cannot cancel before submitting

(You explained the same : Submittable documents, on the other hand, have three different possible values: 0 (Draft), 1 (Submitted), or 2 (Cancelled). It is only possible for a document to move up, from 0->1 or from 1->2.)

Regards,
Mary

Hi there,

Ah, yes, I understand now. You are correct: It is not possible to skip from Draft → Cancelled. Documents must be submitted before they can be cancelled. This is the intended design. If you really need to move from Draft to Cancelled in one step, you will have to use a script of some sort.

Thank you so much

Isn’t there a solution to make it cancelled without custom script?

Structurally, it is not possible to go from Draft → Cancelled. That is deliberate, and any attempt to override that would potentially lead to broken data. For different doctypes, certain transactions and validations take place on submission and cancellation, and you really don’t want to do one without the other.

I would suggest looking at your workflow again to see why you’re trying to skip the Submission step. You say, for example, that the workflow has only 3 steps: “Approved”, “Cancelled”, and “Draft”. What about a document that has been finalized but is still waiting for approval? What state would that be in? Usually, there’s another state called “Submitted” or something similar. Is there a reason you’re skipping that step?

Dear Peter

It is not the case that in my workflow we want to skip the submission.

Consider following scenario which might clarify the case:

  1. Manufacturing head creates stock entry transfer(to transfer material from main warehouse to WIP warehouse)

  2. Stock manager wants to reject it since there is not enough quantity available. He selects reject workflow action.

Here we have to keep the doc status=0 since it is not approved. But what happens then?
In Work Order > Connections > Stock Entry and in each and every report it shows a draft document, draft usually means that something needs to be investigated or something is pending to a decision, but when it is rejected it’s already decided and should not be displayed as pending transactions.

Thanks for your attention,
Mary

Hi Mary, thanks for your clarification.

From a data standpoint, I think you’re approaching this the wrong way. The Draft → Submitted → Cancelled flow means something very specific:

  • Draft: A transaction that has not yet been executed
  • Submitted: A transaction that has been executed (including all consequences to accounting, stock, etc.)
  • Cancelled: A transaction that was previously executed but was later reversed (with reversal of accounting, stock, etc. as well)

In the context of ERPNext, that’s what those terms mean. If a manufacturing head creates a stock entry which is then rejected, Draft is the correct status because the transfer never happened. It would not be correct to say the transfer was reversed.

To do what you want, I suggest approaching this a bit differently. There are a few options:

  1. Create two different workflow states for docstatus=0, one called “Approval Requested” and one called “Rejected”. Both would have a “Draft” status behind the scenes (correctly), but in the UI the two different conditions would be distinguished.
  2. Delete rejected transfers (not a good option, in my opinion).
  3. Let the Stock Manager be in charge of Stock Entries and let the Manufacturing Head use the Material Request doctype. This, I think, is the best option, because it more accurately reflects your real process. The manufacturing head has no direct control over the warehouse, so to let them create a stock entry is a bit counterintuitive. Instead, let them request a transfer, and leave it up to the stock team to respond.

Dear Peter

Thank you so much for your quick concise feedback. What you said is 100% same as what I think and suggest, but my worry is same as what you already mentioned. Deleting documents is not a good way to handle things, because this way we will have gap between documents (document numbering) and nobody would accept the responsibility of his work because he can easily say I have done it, maybe it’s deleted!

All in all, I think ERPNext needs to add another doc status=3 which means rejected status.

Regards,

Mary

The docstatus variable is all about “side effects” (like stock and accounting entries). In those terms, “Draft” and “Rejected” are identical.

What you’re describing is exactly what the workflow process is meant to accomplish. If you want to provide multiple different semantic values to unsubmitted values, workflow states are designed for that purpose. Is there something specific that’s not working for you when you use workflows? You mentioned something about the work order form, but I didn’t fully follow.

Dear Peter

I think with two workarounds we can cover all requirements.

  1. Record the log of deleted documents with the reason why they have deleted.

  2. Not displaying rejected workflow state documents as gray(pending) docs in front of connection > related doc(for example work order>connection>stock entry)

I will really appreciate if you have any idea how to handle these two workarounds.

Thanks and regards,
Mary

I don’t really have any advice, because I don’t think that deleting is ever a good idea.

More importantly, what you’re trying to do won’t solve your problem with the connections view. All documents, regardless of docstatus, show up in connections. Even if they were cancelled, they’d still be there. There’s talk about improving the connections view to allow filtering (by docstatus, workflow_state, etc.), but I’m not sure if there’s any concrete plan for release.

For your use case here, is there a reason you don’t want to use Material Requests? That’s really the correct answer here, I think. Having Manufacturing Heads create stock transfers is not, in my opinion, a good practice.

I support this workaround

Hi

Thanks for reply but how not to display rejected ones? Does it need code or we can provide it via customization of form or something else?

Best regards

in list view? use saved filter

Hi

Maybe didn’t get what you mean, consider that we are talking about connections related to a document

you mean link field? you have to create client script
https://www.frappeframework.com/docs/v13/user/en/guides/app-development/overriding-link-query-by-custom-script

Thanks

Hi Mary, I answered this before but perhaps wasn’t clear.

Right now, there’s no built-in way to customize how document link counts are filtered (as they appear in the “connections header”). That has nothing to do with docstatus or workflow states.