In the workflow implementations such as the Purchase order (PO) workflows, it is mandatory to submit any changes to a document and get completed in order to have the complete impact of those changes. For example, in case of a purchase order for stocked items, inventory transactions (required for posting item arrival journal) are not generated until the workflow is completed. This gives rise to odd scenarios.
When a PO (which was already approved) is cancelled, it doesn't make sense for the user to submit it for approval. But in order to remove the inventory transactions attached to the PO (and its lines), it is necessary to submit the PO for approval and complete the approval.
In order to overcome such scenarios, we need to use the auto-approval and auto-submit (a customization) when a PO is cancelled.
Do that in all the nodes in the workflow. This means, a PO which is cancelled, it will not get assigned to the approver for approval.
In the other part of the fix, in its purest form, run the following job in the AOT every once in a while:
------------------------------------
static void SUPR_AutoSubmitPOWorkflow(Args _args)
{
PurchTable ptbl;
;
while select forupdate ptbl
where ptbl.PurchStatus == PurchStatus::Canceled
&& ptbl.DocumentState == VersioningDocumentState::Draft
{
ttsBegin;
ptbl.submitToWorkflow(workFlowTypeStr(PurchTableTemplate),'Auto submitted');
ttsCommit;
info(ptbl.PurchId);
}
}
--------------------------------------
(this job is for PO workflows, for other workflows, change the workFlowTypeStr input accordingly.
Running this job will submit the workflows for approval and will get completed.
If you want to improve further on this, then you can put this job in an event handler where it gets run everytime the PO status is changed to 'Canceled'. I will try to do that later.
When a PO (which was already approved) is cancelled, it doesn't make sense for the user to submit it for approval. But in order to remove the inventory transactions attached to the PO (and its lines), it is necessary to submit the PO for approval and complete the approval.
In order to overcome such scenarios, we need to use the auto-approval and auto-submit (a customization) when a PO is cancelled.
In the other part of the fix, in its purest form, run the following job in the AOT every once in a while:
------------------------------------
static void SUPR_AutoSubmitPOWorkflow(Args _args)
{
PurchTable ptbl;
;
while select forupdate ptbl
where ptbl.PurchStatus == PurchStatus::Canceled
&& ptbl.DocumentState == VersioningDocumentState::Draft
{
ttsBegin;
ptbl.submitToWorkflow(workFlowTypeStr(PurchTableTemplate),'Auto submitted');
ttsCommit;
info(ptbl.PurchId);
}
}
--------------------------------------
(this job is for PO workflows, for other workflows, change the workFlowTypeStr input accordingly.
Running this job will submit the workflows for approval and will get completed.
If you want to improve further on this, then you can put this job in an event handler where it gets run everytime the PO status is changed to 'Canceled'. I will try to do that later.

No comments:
Post a Comment