Record being submitted into workflow multiple times

16 11 2009

Ok. Heres the problem, you have a workflow setup and everything is working just fine until you discover that a single record e.g. Purchase Requisition seems to have numerous running workflow instances (of the same configuration). How is this possible. Simple. Try this for yourself even on your currently setup workflows, assuming you are using the standard Microsoft Dynamics WorkflowSubmitDialog.

Click on submit on your main form, wait for the comments dialog to appear, change focus back to your main form again and click on submit again. Now click the ok/submit button on your two comments dialogs and unless you have added some extra checking down the line, your record will be submitted into workflow twice, be assigned twice, approved twice (if the approver doesn’t catch on) etc..

So how do you solve this.

Take 1: Add in an additional check after your your .dialogOk() call and before your activateFromWorkflowTemplate() to see if the record has been submitted….. or

Take 2: Assuming you want to make this fix for all your workflows.
1. Open your WorkflowSubmitDialog Form  from your AOT,
2. Override the wait method to look something like the following:

public void wait(boolean _modal=false)
{
  //super(_modal);
  super(true);
}

Now whenever you open up your submit dialog it will prevent the user from clicking submit again by accident or maliciously on the parent form. Unfortunately due to the way the calling of the WorkflowSubmitDialog is structured, it is quite hard to filter up the modal parameter from your submit to workflow class.  So this is my most minimally invasive approach to the problem.

Comments?

Happy Daxing.

Advertisements

Actions

Information

13 responses

4 02 2010
Aman

Hi Jonathan,

I am an AX developer and just recently started working on workflows. And i have read your blog and find it very helpful.

I making a new workflow and getting stuck.
Its a new custom form on which i need to have a basic workflow template with options to Approve and Reject.

The problem is its not refreshing the action bar.
Even after submitting by clicking on “Submit”, its not changing to “Action”, it still shows “Submit”.

Any suggestions would be welcome

Thanks
Aman

4 02 2010
Jonathan Halland

HI Aman. There are a number of ways to go about fixing this. Essentially you need to modify the canSubmitToWorkflow method on your form to return false if the record has already been submitted to workflow. The yellowbar then will no longer display the option to ‘Submit’ any longer. You can accomplish this goal in two ways. Either have a workflow status field on the record that you are submitting which you modify to ‘Submitted’ etc. when click the submit button. You can then do a check in your canSubmittoWorkflow method e.g. if (purchReqTable.Status == PurchReqStatus::Submitted) return false; or you can use try and see if there are any active workitems for the given record and return false if there are. E.G. (haven’t tasted this) select workflowWorkItemTable where workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending && workflowWorkItemTable.RefRecId == purchReqTable.RecId && workflowWorkItemTable.RefTableId == purchReqTable.TableId; if workflowWorkItemTable .RecId return false;

Hope that helps a bit.

4 02 2010
Aman

Yes it worked. :)

I tried the first one.

Basically added a check that if the status is ‘Submitted’, it returns false.

And voila, Action bar updates itself.

Thanks

Now i dont see any options like Approve, Reject in the Actions menu item. I dont know why. It shows only ‘View history’.

I have replicated the SalesCreditLimitApproval workflow from the microsoft pdf on AX 2009.

4 02 2010
Jonathan Halland

You will need to ensure that the workflow batch job is running in order for workitems to be assigned and processed. You can also run the workflow processor manually by using the form tutorial_workflow… under the AOT.

10 02 2010
Aman

Hi Jon,

I know that can be done through code in AX.

But i was thinking if there is any standard built-in feature in workflow. i guess not.

Thanks anyways :)

Aman

11 02 2010
Aman

Hi Jon,

My workflow works fine now but only when i use the ‘Tutorial_WorkflowProcessor’ form.

If i dont use this form, my document stays in ‘Pending’ state after submission. It is never assigned to any approver.

I even have the two batch jobs configured and running, both in the ‘Waiting’ state.

What could be the reason?

Thanks
Aman

16 02 2010
Jonathan

Have you checked the event logs of both the IIS and AOS machines?

4 02 2010
Aman

Got the problem Jon.

One of the batch jobs was stuck in executing, i guess due to my previous trials.

So i deleted both the batch jobs. (Had to comment out the validations code ;))

and recreated both the jobs using the workflow wizard.

Now it works. I can see the options for Approve, reject etc.

Many thanks.

happy daxing!

9 02 2010
Aman

Hi Jon,
I was wondering over a typical scenario.

Is there any settings by which a workflow form can be made uneditable after it has been submitted for approval? Because it doesnt make sense that a document after submission can be left open for editing.

I checked in the standard setup, it is editable.

Any idea?

Thanks
Aman

10 02 2010
Jonathan

Hi Aman, the rules regarding whether a record is editable (and by whom) after being submitted into workflow is entirely up to you, as some people may have a completion step that requires the assignee to be able to edit the record (or just some fields) and others may require that the record is entirely read-only. You can build this logic into your form by setting your datasource to your desired state i.e. read-only on the active method of your data source of your form. E.g.

if (record.status == ‘PendingApproval’)
{
record_ds.editable(false);
}

Hope that helps
Jonathan

23 02 2010
Aman

Hi Jon,

I solved the problem with the batch jobs.

I had two AOS instances in the Server configuration form in Admin.
On one the “Is batch server” checkbox was already checked and on the other was unchecked.
I checked on the other one also. And it worked.

But i wonder why the first one was not working.

Aman

9 07 2012
Deepthi

Hi Jon, i’ve worked on batch jobs and set the batch server enabled, and validated the URL., but still am facing a problem with workflow, am unable to see the purchase requisition status changing from submitted stage to pending completion stage, please help me with this.
@ Deepthi

9 07 2012
Jonathan

Hi Deepthi. You can check that your batch server configurations are setup correctly and that your workflow batch group is connected to the correct batch server.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: