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:


How do I select from table Common in AX?

16 11 2011

Workflow quite often uses fields such as ContextTableId and ContextRecId to reference the original document. I’ve been needing to get hold of the original database record as a Common object from which I can then do various things, but the question is how do i get that common object?

I’ve tried something like this

Common buffer;
select buffer where buffer.TableId == _tableId && buffer.RecId == _recId;

This however always return an empty buffer regardless of whether or not the record does exist. I eventually managed to retrieve a common record with the following method.

Common buffer;
SysDictTable dictTable;
dictTable = new SysDictTable(_tableId); buffer = dictTable.makeRecord(); select buffer where buffer.RecId == _recId;

I’ve needed to do this a couple of times in the past and kept forgetting, so I’m posting it here for myself and who ever else wants to accomplish this. Enjoy!

Workflow in three Easy Steps – New tool by Amer

28 07 2010

As all you workflow developer’s know, creating new workflow templates is a huge job due to the large number of AOT objects that one has to create and link up. Amer has created a new tool to create new workflow templates in just 3 easy steps. Check it out over here.

Congrats Amer. This is sure to help many many people.

How to test if a configuration key is enabled in X++ code

17 11 2009

So the question today is prob an obvious one to many, but I’m including it just for reference in case somebody also couldn’t figure this out.

How do you execute a specific block of code only if a specific configuration key is enabled? Quite simple in fact. X++ has a built in function isConfigurationKeyEnabled(configurationkeynum _key) that can be used for this very purpose. E.G.

if (isConfigurationKeyEnabled(configurationkeynum(PurchReq)))
//insert code here

%d bloggers like this: