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 UserInfo.id == 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 “,userInfo.name, workflowTrackingCommentTable.RecId));
}

}

 

Advertisements

2 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;
    pause;
    }

    [ ]s
    Joyle

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