Determine if a document has an outstanding task.

20 05 2015

In AX2009 you used to have two different status for assigned Purchase Requisitions in workflow, namely: “Pending Completion” and “Pending Approval”. Unfortunately in AX2012 this has become simply “In Review” to signify it being in workflow. This allows a more flexible approach to the ordering and reuse of elements in workflow. However it does not provide a clear way to distinguish where the Purchase Requisition is currently in the workflow process especially whether or not the item is currently assigned as a task or an approval.

The code below provides the X++ select statement to determine whether a document in workflow has at least one pending Task based workitem linked to it.

public display NoYes isTask()
  WorkflowWorkItemTable workflowWorkItemTable;
  WorkflowElementTable workflowElementTable;
  select firstonly ElementId from workflowWorkItemTable
    where workflowWorkItemTable.RefTableId == this.TableId &&
    workflowWorkItemTable.RefRecId == this.RecId &&
    workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending
    join ElementId, ElementType from workflowElementTable
    where workflowElementTable.ElementId == workflowWorkItemTable.ElementId &&
    workflowElementTable.ElementType == WorkflowElementType::Task;
  return (workflowWorkItemTable.RecId == 0) ? NoYes::No : NoYes::Yes;

Note: If you’re using line level workflows or parallel branches you may not be guaranteed that the result is what you are logically looking for. It will simply return if there is at least one pending task workitem linked.

This post was inspired by forum question:


Workflow Tasks VS Approvals

19 04 2010

Have you looked at the tasks and approvals in Dynamics AX workflow and wondered why the two exist? Today we’ll look at a few of the differences and some potential ways in which they can be used in your workflow templates.

1) Approvals:
Approvals are designed for (as the name suggests) approval activities, where for example the document won’t necessarily be modified, mainly just reviewed and approved by one or more people. The approval activity may furthermore require a number of different levels of approval before the document is finally marked as approved.

For example. Contoso has a HR workflow process that requires the line manager to approve a job application, after that finance officer should approve it and finally if the position being applied for is at management level, at least half of the board should approve it.

We can accomplish this fairly simply with a workflow template with a single approval task created and 3 steps configured each being assigned to different people and having different requirements for the step to be started and completed.

2) Tasks
Tasks in Dynamics AX workflow differ from the above described approval activity in a couple of sometimes subtle but important ways.

  • Tasks can be assigned to multiple people, but only one person can complete it.
    Tasks in workflow are mainly designed for activities where the person being assigned the document is required to perform some form of modification to the document or task related to it. Thus only one person should be allowed to do it, in order to prevent conflicts or duplicate work being performed.

E.G. Using the above example: Once the application has been approved, it should then be assigned to an IT technician who has to create the successful applicant’s login details on the company network. Although there may be a whole group of people who can perform this job, only one person must actually do it or we may end-up with multiple accounts being created. This is where tasks come in. The person who configures the workflow can choose to assign the task to the group ‘IT_tech’ (IT technicians), each person will then receive item in their inbox, but only one person will be able to ‘Accept’ the task after which the task will be removed from all the other assignees. The person who then accepted the task can then action it according to how the workflow template was setup.

Note: If the task was configured to only be sent to one person, it will be automatically ‘accepted’.

  • Tasks can have multiple ways of completing or rejecting.
    In workflow there are times where you may want to have various ways to successfully complete a task.

E.G. Contoso has a new job opening. The posting is sent to John for publishing, he is tasked at reviewing the document adding the necessary information and then deciding whether to publish the article to the web or to publish the article internally.

One could either setup the job posting form have additional buttons such as ‘Publish to web’ or ‘Publish internally’ or we could create two completing outcomes in our template to execute these two different pieces of logic. The workflow history would then also maintain a record of what John decided to do.

So to summarise:

Approval Tasks
Assigned to multiple people Yes Yes
Only one person may complete No Yes
Multiple people may complete Yes No
Multiple completion outcomes No Yes
Multiple steps Yes No
Completion rules Yes No

I hope this helps clarify the difference between Workflow tasks and approvals in your minds. Please post any comments or questions about the way that you have used these two tools in Dynamics AX 2009.


%d bloggers like this: