Microsoft Dynamics AX 2012 : Get workflow Last Approver Name and Approved Date

Recently, I have come across an issue where, I need to fetch the last approver ‘s name who approved the workflow document and the approved date.

Note: It can be applied to any workflow document which has workflow enabled like(Journal, Puchase Order, Purch Requistion etc,)

Below is th code

static void Job19(Args _args)

WorkflowTrackingStatusTable workflowTrackingStatus;
WorkflowTrackingTable workflowTrackingTable;
WorkflowTrackingCommentTable workflowTrackingCommentTable;
UserInfo userInfo;

select firstFast RecId, User from workflowTrackingTable
order by RecId desc
join workflowTrackingCommentTable
where workflowTrackingCommentTable.WorkflowTrackingTable == workflowTrackingTable.RecId
join UserInfo
where == WorkflowTrackingTable.User
exists join workflowTrackingStatus
where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatus.RecId
&& workflowTrackingStatus.ContextRecId == _purchRecId //PurchRecID
&& workflowTrackingStatus.ContextTableId == tableNum(PurchTable) //PurchTable
&& workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval;
if (workflowTrackingTable.RecId > 0)

info(strFmt(“%1 – %2 “,, workflowTrackingCommentTable.RecId));




4 responses to “Microsoft Dynamics AX 2012 : Get workflow Last Approver Name and Approved Date

  1. Hi,
    I think there is a easier solution:

    WorkflowTrackingStatusTable workflowTrackingStatusTable;
    WorkflowTrackingTable workflowTrackingTable;

    workflowTrackingStatusTable = Workflow::findTrackingStatusForDocument(myRecord);
    workflowTrackingTable = Workflow::findLastWorkflowTrackingRecord(workflowTrackingStatusTable.CorrelationId);

    print workflowTrackingTable.User;

    [ ]s

  2. hi all.., if i want to update approval date to table purchtable .., can give me solution..

  3. if i want to run this script for update one of the fields inside purchtable , can you give an example

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s