Below code can be used to retrieve last approver name for any workflow activated in Dynamics AX/ 365 Finance and operations.
static void dtGetLastApproverName(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 == _salesRecId //PurchRecID
&& workflowTrackingStatus.ContextTableId == tableNum(SalesTable) //SalesTable
&& workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval;
if (workflowTrackingTable.RecId > 0)
{
info(strFmt(“%1 – %2 “,userInfo.name, workflowTrackingCommentTable.RecId));
}
}